Submission #43658495
Source Code Expand
Copy
import std;void main () {int N = readln.chomp.to!int;string S = readln.chomp;solve(N, S);}void solve (int N, string S) {// dp[i][j] := i文字目に来た時点で、それまでの否定論理和がjである場合の数long[][] dp = new long[][](N, 2);// initializedp[0][] = 0;if (S[0] == '0') {dp[0][0] = 1;} else {dp[0][1] = 1;}foreach (i; 1..N) {
import std; void main () { int N = readln.chomp.to!int; string S = readln.chomp; solve(N, S); } void solve (int N, string S) { // dp[i][j] := i文字目に来た時点で、それまでの否定論理和がjである場合の数 long[][] dp = new long[][](N, 2); // initialize dp[0][] = 0; if (S[0] == '0') { dp[0][0] = 1; } else { dp[0][1] = 1; } foreach (i; 1..N) { if (S[i] == '0') { dp[i][0] = 0; dp[i][1] = dp[i-1][0] + dp[i-1][1]; } else { dp[i][0] = dp[i-1][1]; dp[i][1] = dp[i-1][0]; } dp[i][S[i]-'0']++; } long ans = 0; foreach (i; 0..N) { ans += dp[i][1]; } writeln(ans); }
Submission Info
Submission Time | |
---|---|
Task | E - NAND repeatedly |
User | InTheBloom |
Language | D (DMD 2.091.0) |
Score | 450 |
Code Size | 796 Byte |
Status | AC |
Exec Time | 151 ms |
Memory | 52760 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 450 / 450 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt, 02_handmade_15.txt, 02_handmade_16.txt, 02_handmade_17.txt, 02_handmade_18.txt, 02_handmade_19.txt, 02_handmade_20.txt, 02_handmade_21.txt, 02_handmade_22.txt, 02_handmade_23.txt, 02_handmade_24.txt, 02_handmade_25.txt, 02_handmade_26.txt, 02_handmade_27.txt, 02_handmade_28.txt, 02_handmade_29.txt, 02_handmade_30.txt, 02_handmade_31.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 9 ms | 3568 KB |
00_sample_01.txt | AC | 2 ms | 3560 KB |
01_random_02.txt | AC | 146 ms | 52596 KB |
01_random_03.txt | AC | 148 ms | 52548 KB |
01_random_04.txt | AC | 146 ms | 52388 KB |
01_random_05.txt | AC | 151 ms | 52552 KB |
01_random_06.txt | AC | 148 ms | 52740 KB |
01_random_07.txt | AC | 128 ms | 45756 KB |
01_random_08.txt | AC | 104 ms | 39344 KB |
01_random_09.txt | AC | 102 ms | 38472 KB |
01_random_10.txt | AC | 95 ms | 35736 KB |
01_random_11.txt | AC | 44 ms | 14972 KB |
02_handmade_12.txt | AC | 94 ms | 36884 KB |
02_handmade_13.txt | AC | 96 ms | 36936 KB |
02_handmade_14.txt | AC | 145 ms | 52760 KB |
02_handmade_15.txt | AC | 144 ms | 52472 KB |
02_handmade_16.txt | AC | 146 ms | 52596 KB |
02_handmade_17.txt | AC | 144 ms | 52548 KB |
02_handmade_18.txt | AC | 2 ms | 3388 KB |
02_handmade_19.txt | AC | 3 ms | 3592 KB |
02_handmade_20.txt | AC | 2 ms | 3644 KB |
02_handmade_21.txt | AC | 2 ms | 3548 KB |
02_handmade_22.txt | AC | 2 ms | 3576 KB |
02_handmade_23.txt | AC | 2 ms | 3596 KB |
02_handmade_24.txt | AC | 2 ms | 3548 KB |
02_handmade_25.txt | AC | 2 ms | 3648 KB |
02_handmade_26.txt | AC | 2 ms | 3476 KB |
02_handmade_27.txt | AC | 2 ms | 3584 KB |
02_handmade_28.txt | AC | 2 ms | 3580 KB |
02_handmade_29.txt | AC | 2 ms | 3528 KB |
02_handmade_30.txt | AC | 2 ms | 3600 KB |
02_handmade_31.txt | AC | 2 ms | 3544 KB |