# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874040 |
2023-11-16T08:13:29 Z |
vjudge1 |
Lamps (JOI19_lamps) |
C++17 |
|
54 ms |
27908 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int INF = 1e9;
string s1, s2;
int n, dp[N][3][2], ans = INF;
char f(char c, int i, int j){
if (i != 2) c = i + '0';
if (j) c = '1' + '0' - c;
return c;
}
int main() {
ios:: sync_with_stdio(0), cin.tie(0);
cin >> n >> s1 >> s2;
s1 = 'D' + s1; s2 = 'D' + s2;
memset(dp, 63, sizeof dp);
dp[0][2][0] = 0;
for (int i = 1; i <= n; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 2; k++) {
if (f(s1[i], 0, k) == s2[i]) dp[i][0][k] = min(dp[i][0][k], dp[i-1][j][k] + (j != 0));
if (f(s1[i], 1, k) == s2[i]) dp[i][1][k] = min(dp[i][1][k], dp[i-1][j][k] + (j != 1));
if (f(s1[i], 2, k) == s2[i]) dp[i][2][k] = min(dp[i][2][k], dp[i-1][j][k]);
if (f(s1[i], 0, k ^ 1) == s2[i]) dp[i][0][k ^ 1] = min(dp[i][0][k ^ 1], dp[i - 1][j][k] + (j ^ 0) + !(k ^ 0));
if (f(s1[i], 1, k ^ 1) == s2[i]) dp[i][1][k ^ 1] = min(dp[i][1][k ^ 1], dp[i - 1][j][k] + (j ^ 1) + !(k ^ 0));
if (f(s1[i], 2, k ^ 1) == s2[i]) dp[i][2][k ^ 1] = min(dp[i][2][k ^ 1], dp[i - 1][j][k] + !(k ^ 0));
if (i == n) ans = min(ans, dp[i][j][k]);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
23900 KB |
Output is correct |
2 |
Correct |
3 ms |
23900 KB |
Output is correct |
3 |
Correct |
4 ms |
23896 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
3 ms |
23900 KB |
Output is correct |
6 |
Correct |
4 ms |
23900 KB |
Output is correct |
7 |
Correct |
3 ms |
23900 KB |
Output is correct |
8 |
Correct |
3 ms |
23900 KB |
Output is correct |
9 |
Correct |
3 ms |
23896 KB |
Output is correct |
10 |
Correct |
3 ms |
23896 KB |
Output is correct |
11 |
Correct |
3 ms |
23900 KB |
Output is correct |
12 |
Correct |
3 ms |
23704 KB |
Output is correct |
13 |
Correct |
3 ms |
23900 KB |
Output is correct |
14 |
Correct |
3 ms |
23900 KB |
Output is correct |
15 |
Correct |
3 ms |
23900 KB |
Output is correct |
16 |
Correct |
4 ms |
23900 KB |
Output is correct |
17 |
Correct |
3 ms |
23900 KB |
Output is correct |
18 |
Correct |
3 ms |
23900 KB |
Output is correct |
19 |
Correct |
3 ms |
23900 KB |
Output is correct |
20 |
Correct |
3 ms |
23900 KB |
Output is correct |
21 |
Correct |
3 ms |
23900 KB |
Output is correct |
22 |
Correct |
3 ms |
23900 KB |
Output is correct |
23 |
Correct |
3 ms |
23700 KB |
Output is correct |
24 |
Correct |
3 ms |
23900 KB |
Output is correct |
25 |
Correct |
3 ms |
23900 KB |
Output is correct |
26 |
Correct |
3 ms |
23728 KB |
Output is correct |
27 |
Correct |
4 ms |
23896 KB |
Output is correct |
28 |
Correct |
3 ms |
23900 KB |
Output is correct |
29 |
Correct |
3 ms |
23900 KB |
Output is correct |
30 |
Correct |
3 ms |
23900 KB |
Output is correct |
31 |
Correct |
3 ms |
23900 KB |
Output is correct |
32 |
Correct |
3 ms |
23900 KB |
Output is correct |
33 |
Correct |
3 ms |
23900 KB |
Output is correct |
34 |
Correct |
3 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
23900 KB |
Output is correct |
2 |
Correct |
3 ms |
23900 KB |
Output is correct |
3 |
Correct |
4 ms |
23896 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
3 ms |
23900 KB |
Output is correct |
6 |
Correct |
4 ms |
23900 KB |
Output is correct |
7 |
Correct |
3 ms |
23900 KB |
Output is correct |
8 |
Correct |
3 ms |
23900 KB |
Output is correct |
9 |
Correct |
3 ms |
23896 KB |
Output is correct |
10 |
Correct |
3 ms |
23896 KB |
Output is correct |
11 |
Correct |
3 ms |
23900 KB |
Output is correct |
12 |
Correct |
3 ms |
23704 KB |
Output is correct |
13 |
Correct |
3 ms |
23900 KB |
Output is correct |
14 |
Correct |
3 ms |
23900 KB |
Output is correct |
15 |
Correct |
3 ms |
23900 KB |
Output is correct |
16 |
Correct |
4 ms |
23900 KB |
Output is correct |
17 |
Correct |
3 ms |
23900 KB |
Output is correct |
18 |
Correct |
3 ms |
23900 KB |
Output is correct |
19 |
Correct |
3 ms |
23900 KB |
Output is correct |
20 |
Correct |
3 ms |
23900 KB |
Output is correct |
21 |
Correct |
3 ms |
23900 KB |
Output is correct |
22 |
Correct |
3 ms |
23900 KB |
Output is correct |
23 |
Correct |
3 ms |
23700 KB |
Output is correct |
24 |
Correct |
3 ms |
23900 KB |
Output is correct |
25 |
Correct |
3 ms |
23900 KB |
Output is correct |
26 |
Correct |
3 ms |
23728 KB |
Output is correct |
27 |
Correct |
4 ms |
23896 KB |
Output is correct |
28 |
Correct |
3 ms |
23900 KB |
Output is correct |
29 |
Correct |
3 ms |
23900 KB |
Output is correct |
30 |
Correct |
3 ms |
23900 KB |
Output is correct |
31 |
Correct |
3 ms |
23900 KB |
Output is correct |
32 |
Correct |
3 ms |
23900 KB |
Output is correct |
33 |
Correct |
3 ms |
23900 KB |
Output is correct |
34 |
Correct |
3 ms |
23900 KB |
Output is correct |
35 |
Correct |
3 ms |
23900 KB |
Output is correct |
36 |
Correct |
3 ms |
23900 KB |
Output is correct |
37 |
Correct |
4 ms |
23900 KB |
Output is correct |
38 |
Correct |
4 ms |
23764 KB |
Output is correct |
39 |
Correct |
3 ms |
23704 KB |
Output is correct |
40 |
Correct |
4 ms |
23900 KB |
Output is correct |
41 |
Correct |
3 ms |
23944 KB |
Output is correct |
42 |
Correct |
3 ms |
23900 KB |
Output is correct |
43 |
Correct |
4 ms |
23900 KB |
Output is correct |
44 |
Correct |
3 ms |
23900 KB |
Output is correct |
45 |
Correct |
3 ms |
23900 KB |
Output is correct |
46 |
Correct |
3 ms |
23808 KB |
Output is correct |
47 |
Correct |
4 ms |
23896 KB |
Output is correct |
48 |
Correct |
3 ms |
23900 KB |
Output is correct |
49 |
Correct |
3 ms |
23900 KB |
Output is correct |
50 |
Correct |
3 ms |
23900 KB |
Output is correct |
51 |
Correct |
3 ms |
23956 KB |
Output is correct |
52 |
Correct |
3 ms |
23900 KB |
Output is correct |
53 |
Correct |
3 ms |
23896 KB |
Output is correct |
54 |
Correct |
4 ms |
23896 KB |
Output is correct |
55 |
Correct |
4 ms |
23900 KB |
Output is correct |
56 |
Correct |
4 ms |
23900 KB |
Output is correct |
57 |
Correct |
4 ms |
23900 KB |
Output is correct |
58 |
Correct |
4 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
23900 KB |
Output is correct |
2 |
Correct |
3 ms |
23900 KB |
Output is correct |
3 |
Correct |
3 ms |
23900 KB |
Output is correct |
4 |
Correct |
3 ms |
23900 KB |
Output is correct |
5 |
Correct |
3 ms |
23900 KB |
Output is correct |
6 |
Correct |
3 ms |
23900 KB |
Output is correct |
7 |
Correct |
34 ms |
25860 KB |
Output is correct |
8 |
Correct |
37 ms |
25856 KB |
Output is correct |
9 |
Correct |
37 ms |
27656 KB |
Output is correct |
10 |
Correct |
37 ms |
27652 KB |
Output is correct |
11 |
Correct |
38 ms |
27656 KB |
Output is correct |
12 |
Correct |
36 ms |
27656 KB |
Output is correct |
13 |
Correct |
34 ms |
27628 KB |
Output is correct |
14 |
Correct |
36 ms |
27656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
23900 KB |
Output is correct |
2 |
Correct |
3 ms |
23900 KB |
Output is correct |
3 |
Correct |
4 ms |
23896 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
3 ms |
23900 KB |
Output is correct |
6 |
Correct |
4 ms |
23900 KB |
Output is correct |
7 |
Correct |
3 ms |
23900 KB |
Output is correct |
8 |
Correct |
3 ms |
23900 KB |
Output is correct |
9 |
Correct |
3 ms |
23896 KB |
Output is correct |
10 |
Correct |
3 ms |
23896 KB |
Output is correct |
11 |
Correct |
3 ms |
23900 KB |
Output is correct |
12 |
Correct |
3 ms |
23704 KB |
Output is correct |
13 |
Correct |
3 ms |
23900 KB |
Output is correct |
14 |
Correct |
3 ms |
23900 KB |
Output is correct |
15 |
Correct |
3 ms |
23900 KB |
Output is correct |
16 |
Correct |
4 ms |
23900 KB |
Output is correct |
17 |
Correct |
3 ms |
23900 KB |
Output is correct |
18 |
Correct |
3 ms |
23900 KB |
Output is correct |
19 |
Correct |
3 ms |
23900 KB |
Output is correct |
20 |
Correct |
3 ms |
23900 KB |
Output is correct |
21 |
Correct |
3 ms |
23900 KB |
Output is correct |
22 |
Correct |
3 ms |
23900 KB |
Output is correct |
23 |
Correct |
3 ms |
23700 KB |
Output is correct |
24 |
Correct |
3 ms |
23900 KB |
Output is correct |
25 |
Correct |
3 ms |
23900 KB |
Output is correct |
26 |
Correct |
3 ms |
23728 KB |
Output is correct |
27 |
Correct |
4 ms |
23896 KB |
Output is correct |
28 |
Correct |
3 ms |
23900 KB |
Output is correct |
29 |
Correct |
3 ms |
23900 KB |
Output is correct |
30 |
Correct |
3 ms |
23900 KB |
Output is correct |
31 |
Correct |
3 ms |
23900 KB |
Output is correct |
32 |
Correct |
3 ms |
23900 KB |
Output is correct |
33 |
Correct |
3 ms |
23900 KB |
Output is correct |
34 |
Correct |
3 ms |
23900 KB |
Output is correct |
35 |
Correct |
3 ms |
23900 KB |
Output is correct |
36 |
Correct |
3 ms |
23900 KB |
Output is correct |
37 |
Correct |
4 ms |
23900 KB |
Output is correct |
38 |
Correct |
4 ms |
23764 KB |
Output is correct |
39 |
Correct |
3 ms |
23704 KB |
Output is correct |
40 |
Correct |
4 ms |
23900 KB |
Output is correct |
41 |
Correct |
3 ms |
23944 KB |
Output is correct |
42 |
Correct |
3 ms |
23900 KB |
Output is correct |
43 |
Correct |
4 ms |
23900 KB |
Output is correct |
44 |
Correct |
3 ms |
23900 KB |
Output is correct |
45 |
Correct |
3 ms |
23900 KB |
Output is correct |
46 |
Correct |
3 ms |
23808 KB |
Output is correct |
47 |
Correct |
4 ms |
23896 KB |
Output is correct |
48 |
Correct |
3 ms |
23900 KB |
Output is correct |
49 |
Correct |
3 ms |
23900 KB |
Output is correct |
50 |
Correct |
3 ms |
23900 KB |
Output is correct |
51 |
Correct |
3 ms |
23956 KB |
Output is correct |
52 |
Correct |
3 ms |
23900 KB |
Output is correct |
53 |
Correct |
3 ms |
23896 KB |
Output is correct |
54 |
Correct |
4 ms |
23896 KB |
Output is correct |
55 |
Correct |
4 ms |
23900 KB |
Output is correct |
56 |
Correct |
4 ms |
23900 KB |
Output is correct |
57 |
Correct |
4 ms |
23900 KB |
Output is correct |
58 |
Correct |
4 ms |
23900 KB |
Output is correct |
59 |
Correct |
3 ms |
23900 KB |
Output is correct |
60 |
Correct |
3 ms |
23900 KB |
Output is correct |
61 |
Correct |
3 ms |
23900 KB |
Output is correct |
62 |
Correct |
3 ms |
23900 KB |
Output is correct |
63 |
Correct |
3 ms |
23900 KB |
Output is correct |
64 |
Correct |
3 ms |
23900 KB |
Output is correct |
65 |
Correct |
34 ms |
25860 KB |
Output is correct |
66 |
Correct |
37 ms |
25856 KB |
Output is correct |
67 |
Correct |
37 ms |
27656 KB |
Output is correct |
68 |
Correct |
37 ms |
27652 KB |
Output is correct |
69 |
Correct |
38 ms |
27656 KB |
Output is correct |
70 |
Correct |
36 ms |
27656 KB |
Output is correct |
71 |
Correct |
34 ms |
27628 KB |
Output is correct |
72 |
Correct |
36 ms |
27656 KB |
Output is correct |
73 |
Correct |
35 ms |
27648 KB |
Output is correct |
74 |
Correct |
37 ms |
27648 KB |
Output is correct |
75 |
Correct |
35 ms |
27612 KB |
Output is correct |
76 |
Correct |
43 ms |
27652 KB |
Output is correct |
77 |
Correct |
42 ms |
27636 KB |
Output is correct |
78 |
Correct |
38 ms |
27652 KB |
Output is correct |
79 |
Correct |
37 ms |
27656 KB |
Output is correct |
80 |
Correct |
36 ms |
27636 KB |
Output is correct |
81 |
Correct |
37 ms |
27800 KB |
Output is correct |
82 |
Correct |
38 ms |
27648 KB |
Output is correct |
83 |
Correct |
39 ms |
27652 KB |
Output is correct |
84 |
Correct |
41 ms |
27652 KB |
Output is correct |
85 |
Correct |
39 ms |
27652 KB |
Output is correct |
86 |
Correct |
39 ms |
27724 KB |
Output is correct |
87 |
Correct |
40 ms |
27648 KB |
Output is correct |
88 |
Correct |
44 ms |
27908 KB |
Output is correct |
89 |
Correct |
39 ms |
27644 KB |
Output is correct |
90 |
Correct |
42 ms |
27652 KB |
Output is correct |
91 |
Correct |
42 ms |
27716 KB |
Output is correct |
92 |
Correct |
43 ms |
27652 KB |
Output is correct |
93 |
Correct |
45 ms |
27648 KB |
Output is correct |
94 |
Correct |
54 ms |
27716 KB |
Output is correct |
95 |
Correct |
45 ms |
27648 KB |
Output is correct |
96 |
Correct |
45 ms |
27648 KB |
Output is correct |
97 |
Correct |
45 ms |
27856 KB |
Output is correct |
98 |
Correct |
47 ms |
27652 KB |
Output is correct |
99 |
Correct |
45 ms |
27656 KB |
Output is correct |
100 |
Correct |
46 ms |
27864 KB |
Output is correct |
101 |
Correct |
49 ms |
27652 KB |
Output is correct |
102 |
Correct |
45 ms |
27656 KB |
Output is correct |