# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110504 | 2019-05-11T04:59:22 Z | AngusRitossa | Lamps (JOI19_lamps) | C++14 | 1000 ms | 8660 KB |
#include <bits/stdc++.h> using namespace std; int memo[1000010][2], done[1000010][2], a[1000010], b[1000010], n; int dp(int i, int t) { if (i == n) return 0; if (done[i][t]) return memo[i][t]; done[i][t] = 1; if (a[i] == (b[i]^t)) return memo[i][t] = dp(i+1, t); int ans = dp(i+1, !t) + !t; // Remove/add a toggle, therefore curr is correct int extracost = 1, isok = 1, istoggled = t; for (int j = i; j < n; j++) { if ((b[j] == b[i]) != isok) { isok = !isok; istoggled = !istoggled; if (istoggled) extracost++; } int am = dp(j+1, istoggled)+extracost; ans = min(ans, am); } return memo[i][t] = ans; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { char c; scanf(" %c", &c); a[i] = c-'0'; } for (int i = 0; i < n; i++) { char c; scanf(" %c", &c); b[i] = c-'0'; } for (int i = n-1; i >= 0; i--) { for (int t = 0; t < 2; t++) { if (a[i] == (b[i]^t)) { memo[i][t] = memo[i+1][t]; continue; } int ans = memo[i+1][!t] + !t; // Remove/add a toggle, therefore curr is correct int extracost = 1, isok = 1, istoggled = t; for (int j = i; j < n; j++) { if ((b[j] == b[i]) != isok) { isok = !isok; istoggled = !istoggled; if (istoggled) extracost++; } int am = memo[j+1][istoggled]+extracost; ans = min(ans, am); } memo[i][t] = ans; } } int ans = memo[0][0]; printf("%d\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 3 ms | 384 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 256 KB | Output is correct |
23 | Correct | 3 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 3 ms | 384 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 256 KB | Output is correct |
23 | Correct | 3 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 2 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
36 | Correct | 6 ms | 384 KB | Output is correct |
37 | Correct | 6 ms | 384 KB | Output is correct |
38 | Correct | 6 ms | 384 KB | Output is correct |
39 | Correct | 8 ms | 384 KB | Output is correct |
40 | Correct | 11 ms | 384 KB | Output is correct |
41 | Correct | 9 ms | 384 KB | Output is correct |
42 | Correct | 9 ms | 384 KB | Output is correct |
43 | Correct | 8 ms | 512 KB | Output is correct |
44 | Correct | 8 ms | 384 KB | Output is correct |
45 | Correct | 10 ms | 384 KB | Output is correct |
46 | Correct | 9 ms | 384 KB | Output is correct |
47 | Correct | 12 ms | 384 KB | Output is correct |
48 | Correct | 12 ms | 384 KB | Output is correct |
49 | Correct | 15 ms | 384 KB | Output is correct |
50 | Correct | 15 ms | 384 KB | Output is correct |
51 | Correct | 16 ms | 484 KB | Output is correct |
52 | Correct | 17 ms | 512 KB | Output is correct |
53 | Correct | 20 ms | 440 KB | Output is correct |
54 | Correct | 15 ms | 384 KB | Output is correct |
55 | Correct | 17 ms | 384 KB | Output is correct |
56 | Correct | 15 ms | 384 KB | Output is correct |
57 | Correct | 14 ms | 384 KB | Output is correct |
58 | Correct | 15 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 432 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Execution timed out | 1060 ms | 8660 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 3 ms | 384 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 256 KB | Output is correct |
23 | Correct | 3 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 2 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
36 | Correct | 6 ms | 384 KB | Output is correct |
37 | Correct | 6 ms | 384 KB | Output is correct |
38 | Correct | 6 ms | 384 KB | Output is correct |
39 | Correct | 8 ms | 384 KB | Output is correct |
40 | Correct | 11 ms | 384 KB | Output is correct |
41 | Correct | 9 ms | 384 KB | Output is correct |
42 | Correct | 9 ms | 384 KB | Output is correct |
43 | Correct | 8 ms | 512 KB | Output is correct |
44 | Correct | 8 ms | 384 KB | Output is correct |
45 | Correct | 10 ms | 384 KB | Output is correct |
46 | Correct | 9 ms | 384 KB | Output is correct |
47 | Correct | 12 ms | 384 KB | Output is correct |
48 | Correct | 12 ms | 384 KB | Output is correct |
49 | Correct | 15 ms | 384 KB | Output is correct |
50 | Correct | 15 ms | 384 KB | Output is correct |
51 | Correct | 16 ms | 484 KB | Output is correct |
52 | Correct | 17 ms | 512 KB | Output is correct |
53 | Correct | 20 ms | 440 KB | Output is correct |
54 | Correct | 15 ms | 384 KB | Output is correct |
55 | Correct | 17 ms | 384 KB | Output is correct |
56 | Correct | 15 ms | 384 KB | Output is correct |
57 | Correct | 14 ms | 384 KB | Output is correct |
58 | Correct | 15 ms | 384 KB | Output is correct |
59 | Correct | 2 ms | 384 KB | Output is correct |
60 | Correct | 2 ms | 384 KB | Output is correct |
61 | Correct | 2 ms | 432 KB | Output is correct |
62 | Correct | 3 ms | 384 KB | Output is correct |
63 | Correct | 2 ms | 384 KB | Output is correct |
64 | Correct | 2 ms | 384 KB | Output is correct |
65 | Execution timed out | 1060 ms | 8660 KB | Time limit exceeded |
66 | Halted | 0 ms | 0 KB | - |