# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105081 | 2019-04-10T13:49:52 Z | Just_Solve_The_Problem | Lamps (JOI19_lamps) | C++11 | 155 ms | 16636 KB |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 7; string a, b; int n; int dp[N][3]; /* dp[pos][operation] operation 0 = off 1 = on 2 = do not touch */ char make(char c, int i) { if (i < 2) return i + '0'; return c; } main() { memset(dp, 63, sizeof dp); scanf("%d", &n); cin >> a >> b; a = " " + a; b = " " + b; dp[0][2] = 0; int cost; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { for (int l = 0; l < 3; l++) { cost = dp[i - 1][j]; if (j != l && l != 2) cost++; if ((i == 1 || make(a[i - 1], j) == b[i - 1]) && make(a[i], l) != b[i]) cost++; dp[i][l] = min(dp[i][l], cost); } } } printf("%d\n", min(dp[n][0], min(dp[n][1], dp[n][2]))); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12032 KB | Output is correct |
2 | Correct | 14 ms | 12028 KB | Output is correct |
3 | Correct | 13 ms | 12000 KB | Output is correct |
4 | Correct | 13 ms | 12032 KB | Output is correct |
5 | Correct | 15 ms | 12032 KB | Output is correct |
6 | Correct | 13 ms | 12072 KB | Output is correct |
7 | Correct | 13 ms | 12104 KB | Output is correct |
8 | Correct | 12 ms | 12020 KB | Output is correct |
9 | Correct | 13 ms | 12040 KB | Output is correct |
10 | Correct | 12 ms | 12032 KB | Output is correct |
11 | Correct | 14 ms | 12032 KB | Output is correct |
12 | Correct | 12 ms | 12004 KB | Output is correct |
13 | Correct | 13 ms | 12004 KB | Output is correct |
14 | Correct | 15 ms | 12060 KB | Output is correct |
15 | Correct | 9 ms | 12032 KB | Output is correct |
16 | Correct | 11 ms | 12032 KB | Output is correct |
17 | Correct | 13 ms | 12032 KB | Output is correct |
18 | Correct | 13 ms | 12032 KB | Output is correct |
19 | Correct | 12 ms | 12032 KB | Output is correct |
20 | Correct | 13 ms | 12004 KB | Output is correct |
21 | Correct | 15 ms | 12004 KB | Output is correct |
22 | Correct | 15 ms | 12032 KB | Output is correct |
23 | Correct | 22 ms | 12176 KB | Output is correct |
24 | Correct | 13 ms | 12032 KB | Output is correct |
25 | Correct | 15 ms | 12004 KB | Output is correct |
26 | Correct | 14 ms | 12024 KB | Output is correct |
27 | Correct | 12 ms | 12080 KB | Output is correct |
28 | Correct | 12 ms | 12032 KB | Output is correct |
29 | Correct | 13 ms | 11988 KB | Output is correct |
30 | Correct | 13 ms | 12032 KB | Output is correct |
31 | Correct | 14 ms | 12004 KB | Output is correct |
32 | Correct | 14 ms | 12032 KB | Output is correct |
33 | Correct | 13 ms | 12004 KB | Output is correct |
34 | Correct | 15 ms | 12032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12032 KB | Output is correct |
2 | Correct | 14 ms | 12028 KB | Output is correct |
3 | Correct | 13 ms | 12000 KB | Output is correct |
4 | Correct | 13 ms | 12032 KB | Output is correct |
5 | Correct | 15 ms | 12032 KB | Output is correct |
6 | Correct | 13 ms | 12072 KB | Output is correct |
7 | Correct | 13 ms | 12104 KB | Output is correct |
8 | Correct | 12 ms | 12020 KB | Output is correct |
9 | Correct | 13 ms | 12040 KB | Output is correct |
10 | Correct | 12 ms | 12032 KB | Output is correct |
11 | Correct | 14 ms | 12032 KB | Output is correct |
12 | Correct | 12 ms | 12004 KB | Output is correct |
13 | Correct | 13 ms | 12004 KB | Output is correct |
14 | Correct | 15 ms | 12060 KB | Output is correct |
15 | Correct | 9 ms | 12032 KB | Output is correct |
16 | Correct | 11 ms | 12032 KB | Output is correct |
17 | Correct | 13 ms | 12032 KB | Output is correct |
18 | Correct | 13 ms | 12032 KB | Output is correct |
19 | Correct | 12 ms | 12032 KB | Output is correct |
20 | Correct | 13 ms | 12004 KB | Output is correct |
21 | Correct | 15 ms | 12004 KB | Output is correct |
22 | Correct | 15 ms | 12032 KB | Output is correct |
23 | Correct | 22 ms | 12176 KB | Output is correct |
24 | Correct | 13 ms | 12032 KB | Output is correct |
25 | Correct | 15 ms | 12004 KB | Output is correct |
26 | Correct | 14 ms | 12024 KB | Output is correct |
27 | Correct | 12 ms | 12080 KB | Output is correct |
28 | Correct | 12 ms | 12032 KB | Output is correct |
29 | Correct | 13 ms | 11988 KB | Output is correct |
30 | Correct | 13 ms | 12032 KB | Output is correct |
31 | Correct | 14 ms | 12004 KB | Output is correct |
32 | Correct | 14 ms | 12032 KB | Output is correct |
33 | Correct | 13 ms | 12004 KB | Output is correct |
34 | Correct | 15 ms | 12032 KB | Output is correct |
35 | Correct | 13 ms | 12032 KB | Output is correct |
36 | Correct | 14 ms | 12032 KB | Output is correct |
37 | Correct | 14 ms | 12032 KB | Output is correct |
38 | Correct | 14 ms | 12032 KB | Output is correct |
39 | Correct | 12 ms | 12004 KB | Output is correct |
40 | Correct | 10 ms | 12084 KB | Output is correct |
41 | Correct | 14 ms | 12096 KB | Output is correct |
42 | Correct | 13 ms | 12032 KB | Output is correct |
43 | Correct | 14 ms | 12004 KB | Output is correct |
44 | Correct | 12 ms | 12096 KB | Output is correct |
45 | Correct | 14 ms | 12032 KB | Output is correct |
46 | Correct | 15 ms | 12032 KB | Output is correct |
47 | Correct | 16 ms | 12112 KB | Output is correct |
48 | Correct | 12 ms | 12032 KB | Output is correct |
49 | Correct | 14 ms | 12032 KB | Output is correct |
50 | Correct | 12 ms | 12032 KB | Output is correct |
51 | Correct | 14 ms | 12032 KB | Output is correct |
52 | Correct | 13 ms | 12032 KB | Output is correct |
53 | Correct | 14 ms | 12032 KB | Output is correct |
54 | Correct | 14 ms | 12032 KB | Output is correct |
55 | Correct | 13 ms | 11904 KB | Output is correct |
56 | Correct | 14 ms | 12032 KB | Output is correct |
57 | Correct | 14 ms | 12044 KB | Output is correct |
58 | Correct | 15 ms | 12032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12032 KB | Output is correct |
2 | Correct | 13 ms | 12032 KB | Output is correct |
3 | Correct | 15 ms | 12004 KB | Output is correct |
4 | Correct | 15 ms | 12032 KB | Output is correct |
5 | Correct | 14 ms | 12032 KB | Output is correct |
6 | Correct | 15 ms | 12000 KB | Output is correct |
7 | Correct | 129 ms | 16596 KB | Output is correct |
8 | Correct | 128 ms | 16448 KB | Output is correct |
9 | Correct | 121 ms | 16488 KB | Output is correct |
10 | Correct | 113 ms | 16460 KB | Output is correct |
11 | Correct | 118 ms | 16492 KB | Output is correct |
12 | Correct | 128 ms | 16636 KB | Output is correct |
13 | Correct | 129 ms | 16524 KB | Output is correct |
14 | Correct | 113 ms | 16488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12032 KB | Output is correct |
2 | Correct | 14 ms | 12028 KB | Output is correct |
3 | Correct | 13 ms | 12000 KB | Output is correct |
4 | Correct | 13 ms | 12032 KB | Output is correct |
5 | Correct | 15 ms | 12032 KB | Output is correct |
6 | Correct | 13 ms | 12072 KB | Output is correct |
7 | Correct | 13 ms | 12104 KB | Output is correct |
8 | Correct | 12 ms | 12020 KB | Output is correct |
9 | Correct | 13 ms | 12040 KB | Output is correct |
10 | Correct | 12 ms | 12032 KB | Output is correct |
11 | Correct | 14 ms | 12032 KB | Output is correct |
12 | Correct | 12 ms | 12004 KB | Output is correct |
13 | Correct | 13 ms | 12004 KB | Output is correct |
14 | Correct | 15 ms | 12060 KB | Output is correct |
15 | Correct | 9 ms | 12032 KB | Output is correct |
16 | Correct | 11 ms | 12032 KB | Output is correct |
17 | Correct | 13 ms | 12032 KB | Output is correct |
18 | Correct | 13 ms | 12032 KB | Output is correct |
19 | Correct | 12 ms | 12032 KB | Output is correct |
20 | Correct | 13 ms | 12004 KB | Output is correct |
21 | Correct | 15 ms | 12004 KB | Output is correct |
22 | Correct | 15 ms | 12032 KB | Output is correct |
23 | Correct | 22 ms | 12176 KB | Output is correct |
24 | Correct | 13 ms | 12032 KB | Output is correct |
25 | Correct | 15 ms | 12004 KB | Output is correct |
26 | Correct | 14 ms | 12024 KB | Output is correct |
27 | Correct | 12 ms | 12080 KB | Output is correct |
28 | Correct | 12 ms | 12032 KB | Output is correct |
29 | Correct | 13 ms | 11988 KB | Output is correct |
30 | Correct | 13 ms | 12032 KB | Output is correct |
31 | Correct | 14 ms | 12004 KB | Output is correct |
32 | Correct | 14 ms | 12032 KB | Output is correct |
33 | Correct | 13 ms | 12004 KB | Output is correct |
34 | Correct | 15 ms | 12032 KB | Output is correct |
35 | Correct | 13 ms | 12032 KB | Output is correct |
36 | Correct | 14 ms | 12032 KB | Output is correct |
37 | Correct | 14 ms | 12032 KB | Output is correct |
38 | Correct | 14 ms | 12032 KB | Output is correct |
39 | Correct | 12 ms | 12004 KB | Output is correct |
40 | Correct | 10 ms | 12084 KB | Output is correct |
41 | Correct | 14 ms | 12096 KB | Output is correct |
42 | Correct | 13 ms | 12032 KB | Output is correct |
43 | Correct | 14 ms | 12004 KB | Output is correct |
44 | Correct | 12 ms | 12096 KB | Output is correct |
45 | Correct | 14 ms | 12032 KB | Output is correct |
46 | Correct | 15 ms | 12032 KB | Output is correct |
47 | Correct | 16 ms | 12112 KB | Output is correct |
48 | Correct | 12 ms | 12032 KB | Output is correct |
49 | Correct | 14 ms | 12032 KB | Output is correct |
50 | Correct | 12 ms | 12032 KB | Output is correct |
51 | Correct | 14 ms | 12032 KB | Output is correct |
52 | Correct | 13 ms | 12032 KB | Output is correct |
53 | Correct | 14 ms | 12032 KB | Output is correct |
54 | Correct | 14 ms | 12032 KB | Output is correct |
55 | Correct | 13 ms | 11904 KB | Output is correct |
56 | Correct | 14 ms | 12032 KB | Output is correct |
57 | Correct | 14 ms | 12044 KB | Output is correct |
58 | Correct | 15 ms | 12032 KB | Output is correct |
59 | Correct | 13 ms | 12032 KB | Output is correct |
60 | Correct | 13 ms | 12032 KB | Output is correct |
61 | Correct | 15 ms | 12004 KB | Output is correct |
62 | Correct | 15 ms | 12032 KB | Output is correct |
63 | Correct | 14 ms | 12032 KB | Output is correct |
64 | Correct | 15 ms | 12000 KB | Output is correct |
65 | Correct | 129 ms | 16596 KB | Output is correct |
66 | Correct | 128 ms | 16448 KB | Output is correct |
67 | Correct | 121 ms | 16488 KB | Output is correct |
68 | Correct | 113 ms | 16460 KB | Output is correct |
69 | Correct | 118 ms | 16492 KB | Output is correct |
70 | Correct | 128 ms | 16636 KB | Output is correct |
71 | Correct | 129 ms | 16524 KB | Output is correct |
72 | Correct | 113 ms | 16488 KB | Output is correct |
73 | Correct | 112 ms | 16556 KB | Output is correct |
74 | Correct | 119 ms | 16492 KB | Output is correct |
75 | Correct | 115 ms | 16488 KB | Output is correct |
76 | Correct | 106 ms | 16488 KB | Output is correct |
77 | Correct | 108 ms | 16616 KB | Output is correct |
78 | Correct | 124 ms | 16448 KB | Output is correct |
79 | Correct | 121 ms | 16516 KB | Output is correct |
80 | Correct | 109 ms | 16488 KB | Output is correct |
81 | Correct | 114 ms | 16488 KB | Output is correct |
82 | Correct | 120 ms | 16492 KB | Output is correct |
83 | Correct | 109 ms | 16488 KB | Output is correct |
84 | Correct | 121 ms | 16488 KB | Output is correct |
85 | Correct | 147 ms | 16436 KB | Output is correct |
86 | Correct | 120 ms | 16488 KB | Output is correct |
87 | Correct | 155 ms | 16492 KB | Output is correct |
88 | Correct | 117 ms | 16488 KB | Output is correct |
89 | Correct | 131 ms | 16588 KB | Output is correct |
90 | Correct | 128 ms | 16464 KB | Output is correct |
91 | Correct | 125 ms | 16484 KB | Output is correct |
92 | Correct | 113 ms | 16484 KB | Output is correct |
93 | Correct | 124 ms | 16408 KB | Output is correct |
94 | Correct | 132 ms | 16508 KB | Output is correct |
95 | Correct | 141 ms | 16488 KB | Output is correct |
96 | Correct | 134 ms | 16488 KB | Output is correct |
97 | Correct | 129 ms | 16500 KB | Output is correct |
98 | Correct | 124 ms | 16456 KB | Output is correct |
99 | Correct | 122 ms | 16408 KB | Output is correct |
100 | Correct | 132 ms | 16456 KB | Output is correct |
101 | Correct | 131 ms | 16468 KB | Output is correct |
102 | Correct | 136 ms | 16488 KB | Output is correct |