#include<stdio.h>
char a[1212121], b[1212121];
int D[1212121][6];
int min(int a, int b) { if (a < b)return a; return b; }
int main() {
int n, i, j; scanf("%d%s%s", &n,a+1,b+1);
D[0][0] = D[0][1] = D[0][2] = D[0][3] = D[0][4] = 1e9;
for (i = 1; i <= n; i++) {
if (b[i] != '0')D[i][0] = 1e9;
else D[i][0] = min(min(min(D[i - 1][0], D[i - 1][1] + 1), D[i - 1][4] + 1), D[i - 1][5] + 1);
if (b[i] != '1')D[i][1] = 1e9;
else D[i][1] = min(min(min(D[i - 1][1], D[i - 1][0] + 1), D[i - 1][4] + 1), D[i - 1][5] + 1);
if (b[i] != '0')D[i][2] = 1e9;
else D[i][2] = min(min(D[i - 1][2], D[i - 1][3] + 1), D[i - 1][4] + 1);
if (b[i] != '1')D[i][3] = 1e9;
else D[i][3] = min(min(D[i - 1][3], D[i - 1][2] + 1), D[i - 1][4] + 1);
if (a[i] == b[i]) D[i][4] = 1e9;
else D[i][4] = min(min(min(min(min(D[i - 1][4], D[i - 1][0] + 1), D[i - 1][1] + 1), D[i - 1][2]), D[i - 1][3]), D[i - 1][5] + 1);
if (a[i] != b[i])D[i][5] = 1e9;
else D[i][5] = min(min(min(min(min(D[i - 1][0], D[i - 1][1]), D[i - 1][2]), D[i - 1][3]), D[i - 1][4]), D[i - 1][5]);
}
printf("%d", min(min(min(min(min(D[n][0], D[n][1]), D[n][2]), D[n][3]),D[n][4]),D[n][5]));
return 0;
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:7:12: warning: unused variable 'j' [-Wunused-variable]
int n, i, j; scanf("%d%s%s", &n,a+1,b+1);
^
lamp.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int n, i, j; scanf("%d%s%s", &n,a+1,b+1);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
35 ms |
26360 KB |
Output is correct |
8 |
Correct |
34 ms |
26360 KB |
Output is correct |
9 |
Correct |
33 ms |
26360 KB |
Output is correct |
10 |
Correct |
34 ms |
26360 KB |
Output is correct |
11 |
Correct |
34 ms |
26360 KB |
Output is correct |
12 |
Correct |
35 ms |
26360 KB |
Output is correct |
13 |
Correct |
34 ms |
26360 KB |
Output is correct |
14 |
Correct |
35 ms |
26360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |