#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 7;
string a, b;
int n;
int dp[N][3][2];
/*
dp[pos][operation][xor]
operation
0 = off
1 = on
2 = do not touch
*/
main() {
memset(dp, 63, sizeof dp);
scanf("%d", &n);
cin >> a >> b;
a = " " + a;
b = " " + b;
dp[0][2][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++) {
if (b[i] - '0' == j) {
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0]);
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][1]);
for (int l = 0; l < 3; l++) {
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][l][0] + 1);
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][l][1] + 1);
}
}
if (b[i] - '0' == (j ^ 1)) {
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]);
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + 1);
for (int l = 0; l < 3; l++) {
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][l][1] + 1);
}
}
if (j == 2 && b[i] == a[i]) {
for (int l = 0; l < 3; l++) {
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][l][0]);
dp[i][j][0] = min(dp[i][j][0], dp[i - 1][l][1]);
}
}
if (j == 2 && b[i] != a[i]) {
for (int l = 0; l < 3; l++) {
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][l][0] + 1);
dp[i][j][1] = min(dp[i][j][1], dp[i - 1][l][1]);
}
}
}
}
int ans = dp[0][1][0];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
ans = min(ans, dp[n][i][j]);
}
}
printf("%d\n", ans);
}
Compilation message
lamp.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
lamp.cpp: In function 'int main()':
lamp.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23808 KB |
Output is correct |
2 |
Correct |
23 ms |
23808 KB |
Output is correct |
3 |
Correct |
23 ms |
23800 KB |
Output is correct |
4 |
Correct |
24 ms |
23808 KB |
Output is correct |
5 |
Correct |
23 ms |
23772 KB |
Output is correct |
6 |
Correct |
24 ms |
23808 KB |
Output is correct |
7 |
Correct |
21 ms |
23800 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
23808 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
23 ms |
23808 KB |
Output is correct |
12 |
Correct |
25 ms |
23784 KB |
Output is correct |
13 |
Correct |
22 ms |
23800 KB |
Output is correct |
14 |
Correct |
23 ms |
23780 KB |
Output is correct |
15 |
Correct |
23 ms |
23808 KB |
Output is correct |
16 |
Correct |
24 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
23800 KB |
Output is correct |
18 |
Correct |
22 ms |
23800 KB |
Output is correct |
19 |
Correct |
22 ms |
23808 KB |
Output is correct |
20 |
Correct |
27 ms |
23936 KB |
Output is correct |
21 |
Correct |
24 ms |
23808 KB |
Output is correct |
22 |
Correct |
23 ms |
23808 KB |
Output is correct |
23 |
Correct |
26 ms |
23800 KB |
Output is correct |
24 |
Correct |
22 ms |
23808 KB |
Output is correct |
25 |
Correct |
21 ms |
23808 KB |
Output is correct |
26 |
Correct |
23 ms |
23808 KB |
Output is correct |
27 |
Correct |
23 ms |
23808 KB |
Output is correct |
28 |
Correct |
24 ms |
23808 KB |
Output is correct |
29 |
Correct |
22 ms |
23808 KB |
Output is correct |
30 |
Correct |
26 ms |
23800 KB |
Output is correct |
31 |
Correct |
22 ms |
23800 KB |
Output is correct |
32 |
Correct |
24 ms |
23808 KB |
Output is correct |
33 |
Correct |
21 ms |
23800 KB |
Output is correct |
34 |
Correct |
23 ms |
23772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23808 KB |
Output is correct |
2 |
Correct |
23 ms |
23808 KB |
Output is correct |
3 |
Correct |
23 ms |
23800 KB |
Output is correct |
4 |
Correct |
24 ms |
23808 KB |
Output is correct |
5 |
Correct |
23 ms |
23772 KB |
Output is correct |
6 |
Correct |
24 ms |
23808 KB |
Output is correct |
7 |
Correct |
21 ms |
23800 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
23808 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
23 ms |
23808 KB |
Output is correct |
12 |
Correct |
25 ms |
23784 KB |
Output is correct |
13 |
Correct |
22 ms |
23800 KB |
Output is correct |
14 |
Correct |
23 ms |
23780 KB |
Output is correct |
15 |
Correct |
23 ms |
23808 KB |
Output is correct |
16 |
Correct |
24 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
23800 KB |
Output is correct |
18 |
Correct |
22 ms |
23800 KB |
Output is correct |
19 |
Correct |
22 ms |
23808 KB |
Output is correct |
20 |
Correct |
27 ms |
23936 KB |
Output is correct |
21 |
Correct |
24 ms |
23808 KB |
Output is correct |
22 |
Correct |
23 ms |
23808 KB |
Output is correct |
23 |
Correct |
26 ms |
23800 KB |
Output is correct |
24 |
Correct |
22 ms |
23808 KB |
Output is correct |
25 |
Correct |
21 ms |
23808 KB |
Output is correct |
26 |
Correct |
23 ms |
23808 KB |
Output is correct |
27 |
Correct |
23 ms |
23808 KB |
Output is correct |
28 |
Correct |
24 ms |
23808 KB |
Output is correct |
29 |
Correct |
22 ms |
23808 KB |
Output is correct |
30 |
Correct |
26 ms |
23800 KB |
Output is correct |
31 |
Correct |
22 ms |
23800 KB |
Output is correct |
32 |
Correct |
24 ms |
23808 KB |
Output is correct |
33 |
Correct |
21 ms |
23800 KB |
Output is correct |
34 |
Correct |
23 ms |
23772 KB |
Output is correct |
35 |
Correct |
23 ms |
23840 KB |
Output is correct |
36 |
Correct |
26 ms |
23752 KB |
Output is correct |
37 |
Correct |
24 ms |
23884 KB |
Output is correct |
38 |
Correct |
25 ms |
23808 KB |
Output is correct |
39 |
Correct |
23 ms |
23808 KB |
Output is correct |
40 |
Correct |
23 ms |
23808 KB |
Output is correct |
41 |
Correct |
27 ms |
23808 KB |
Output is correct |
42 |
Correct |
24 ms |
23808 KB |
Output is correct |
43 |
Correct |
23 ms |
23800 KB |
Output is correct |
44 |
Correct |
23 ms |
23808 KB |
Output is correct |
45 |
Correct |
27 ms |
23800 KB |
Output is correct |
46 |
Correct |
19 ms |
23808 KB |
Output is correct |
47 |
Correct |
24 ms |
23780 KB |
Output is correct |
48 |
Correct |
23 ms |
23808 KB |
Output is correct |
49 |
Correct |
27 ms |
23852 KB |
Output is correct |
50 |
Correct |
27 ms |
23808 KB |
Output is correct |
51 |
Correct |
22 ms |
23928 KB |
Output is correct |
52 |
Correct |
25 ms |
23808 KB |
Output is correct |
53 |
Correct |
23 ms |
23936 KB |
Output is correct |
54 |
Correct |
21 ms |
23808 KB |
Output is correct |
55 |
Correct |
23 ms |
23936 KB |
Output is correct |
56 |
Correct |
23 ms |
23808 KB |
Output is correct |
57 |
Correct |
23 ms |
23808 KB |
Output is correct |
58 |
Correct |
22 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
22 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23808 KB |
Output is correct |
4 |
Correct |
23 ms |
23808 KB |
Output is correct |
5 |
Correct |
23 ms |
23808 KB |
Output is correct |
6 |
Correct |
22 ms |
23808 KB |
Output is correct |
7 |
Correct |
144 ms |
28108 KB |
Output is correct |
8 |
Correct |
110 ms |
28268 KB |
Output is correct |
9 |
Correct |
126 ms |
28312 KB |
Output is correct |
10 |
Correct |
107 ms |
28268 KB |
Output is correct |
11 |
Correct |
101 ms |
28268 KB |
Output is correct |
12 |
Correct |
108 ms |
28344 KB |
Output is correct |
13 |
Correct |
114 ms |
28228 KB |
Output is correct |
14 |
Correct |
124 ms |
28268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23808 KB |
Output is correct |
2 |
Correct |
23 ms |
23808 KB |
Output is correct |
3 |
Correct |
23 ms |
23800 KB |
Output is correct |
4 |
Correct |
24 ms |
23808 KB |
Output is correct |
5 |
Correct |
23 ms |
23772 KB |
Output is correct |
6 |
Correct |
24 ms |
23808 KB |
Output is correct |
7 |
Correct |
21 ms |
23800 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
22 ms |
23808 KB |
Output is correct |
10 |
Correct |
23 ms |
23800 KB |
Output is correct |
11 |
Correct |
23 ms |
23808 KB |
Output is correct |
12 |
Correct |
25 ms |
23784 KB |
Output is correct |
13 |
Correct |
22 ms |
23800 KB |
Output is correct |
14 |
Correct |
23 ms |
23780 KB |
Output is correct |
15 |
Correct |
23 ms |
23808 KB |
Output is correct |
16 |
Correct |
24 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
23800 KB |
Output is correct |
18 |
Correct |
22 ms |
23800 KB |
Output is correct |
19 |
Correct |
22 ms |
23808 KB |
Output is correct |
20 |
Correct |
27 ms |
23936 KB |
Output is correct |
21 |
Correct |
24 ms |
23808 KB |
Output is correct |
22 |
Correct |
23 ms |
23808 KB |
Output is correct |
23 |
Correct |
26 ms |
23800 KB |
Output is correct |
24 |
Correct |
22 ms |
23808 KB |
Output is correct |
25 |
Correct |
21 ms |
23808 KB |
Output is correct |
26 |
Correct |
23 ms |
23808 KB |
Output is correct |
27 |
Correct |
23 ms |
23808 KB |
Output is correct |
28 |
Correct |
24 ms |
23808 KB |
Output is correct |
29 |
Correct |
22 ms |
23808 KB |
Output is correct |
30 |
Correct |
26 ms |
23800 KB |
Output is correct |
31 |
Correct |
22 ms |
23800 KB |
Output is correct |
32 |
Correct |
24 ms |
23808 KB |
Output is correct |
33 |
Correct |
21 ms |
23800 KB |
Output is correct |
34 |
Correct |
23 ms |
23772 KB |
Output is correct |
35 |
Correct |
23 ms |
23840 KB |
Output is correct |
36 |
Correct |
26 ms |
23752 KB |
Output is correct |
37 |
Correct |
24 ms |
23884 KB |
Output is correct |
38 |
Correct |
25 ms |
23808 KB |
Output is correct |
39 |
Correct |
23 ms |
23808 KB |
Output is correct |
40 |
Correct |
23 ms |
23808 KB |
Output is correct |
41 |
Correct |
27 ms |
23808 KB |
Output is correct |
42 |
Correct |
24 ms |
23808 KB |
Output is correct |
43 |
Correct |
23 ms |
23800 KB |
Output is correct |
44 |
Correct |
23 ms |
23808 KB |
Output is correct |
45 |
Correct |
27 ms |
23800 KB |
Output is correct |
46 |
Correct |
19 ms |
23808 KB |
Output is correct |
47 |
Correct |
24 ms |
23780 KB |
Output is correct |
48 |
Correct |
23 ms |
23808 KB |
Output is correct |
49 |
Correct |
27 ms |
23852 KB |
Output is correct |
50 |
Correct |
27 ms |
23808 KB |
Output is correct |
51 |
Correct |
22 ms |
23928 KB |
Output is correct |
52 |
Correct |
25 ms |
23808 KB |
Output is correct |
53 |
Correct |
23 ms |
23936 KB |
Output is correct |
54 |
Correct |
21 ms |
23808 KB |
Output is correct |
55 |
Correct |
23 ms |
23936 KB |
Output is correct |
56 |
Correct |
23 ms |
23808 KB |
Output is correct |
57 |
Correct |
23 ms |
23808 KB |
Output is correct |
58 |
Correct |
22 ms |
23800 KB |
Output is correct |
59 |
Correct |
23 ms |
23800 KB |
Output is correct |
60 |
Correct |
22 ms |
23800 KB |
Output is correct |
61 |
Correct |
22 ms |
23808 KB |
Output is correct |
62 |
Correct |
23 ms |
23808 KB |
Output is correct |
63 |
Correct |
23 ms |
23808 KB |
Output is correct |
64 |
Correct |
22 ms |
23808 KB |
Output is correct |
65 |
Correct |
144 ms |
28108 KB |
Output is correct |
66 |
Correct |
110 ms |
28268 KB |
Output is correct |
67 |
Correct |
126 ms |
28312 KB |
Output is correct |
68 |
Correct |
107 ms |
28268 KB |
Output is correct |
69 |
Correct |
101 ms |
28268 KB |
Output is correct |
70 |
Correct |
108 ms |
28344 KB |
Output is correct |
71 |
Correct |
114 ms |
28228 KB |
Output is correct |
72 |
Correct |
124 ms |
28268 KB |
Output is correct |
73 |
Correct |
122 ms |
28236 KB |
Output is correct |
74 |
Correct |
115 ms |
28060 KB |
Output is correct |
75 |
Correct |
124 ms |
27980 KB |
Output is correct |
76 |
Correct |
99 ms |
28008 KB |
Output is correct |
77 |
Correct |
107 ms |
28008 KB |
Output is correct |
78 |
Correct |
127 ms |
28008 KB |
Output is correct |
79 |
Correct |
120 ms |
28032 KB |
Output is correct |
80 |
Correct |
120 ms |
27984 KB |
Output is correct |
81 |
Correct |
116 ms |
27988 KB |
Output is correct |
82 |
Correct |
110 ms |
28300 KB |
Output is correct |
83 |
Correct |
107 ms |
28092 KB |
Output is correct |
84 |
Correct |
113 ms |
28008 KB |
Output is correct |
85 |
Correct |
123 ms |
27940 KB |
Output is correct |
86 |
Correct |
114 ms |
28080 KB |
Output is correct |
87 |
Correct |
157 ms |
28108 KB |
Output is correct |
88 |
Correct |
187 ms |
27924 KB |
Output is correct |
89 |
Correct |
119 ms |
28008 KB |
Output is correct |
90 |
Correct |
163 ms |
27980 KB |
Output is correct |
91 |
Correct |
160 ms |
28008 KB |
Output is correct |
92 |
Correct |
128 ms |
28008 KB |
Output is correct |
93 |
Correct |
110 ms |
28004 KB |
Output is correct |
94 |
Correct |
148 ms |
28012 KB |
Output is correct |
95 |
Correct |
131 ms |
28036 KB |
Output is correct |
96 |
Correct |
114 ms |
27832 KB |
Output is correct |
97 |
Correct |
118 ms |
28008 KB |
Output is correct |
98 |
Correct |
115 ms |
28056 KB |
Output is correct |
99 |
Correct |
145 ms |
27996 KB |
Output is correct |
100 |
Correct |
159 ms |
28028 KB |
Output is correct |
101 |
Correct |
135 ms |
27980 KB |
Output is correct |
102 |
Correct |
116 ms |
28120 KB |
Output is correct |