#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 1000006;
int n;
char a[MAXN], b[MAXN];
int dp[MAXN][6];
int solve(int n, int opt){
int& r = dp[n][opt];
if(r == -1){
r = n;
switch(opt){
case 0:
if(a[n-1] == b[n-1]){
r = min(r, solve(n-1, 0));
}else{
r = min(r, solve(n-1, 1) + 1);
}
if(b[n-1] == '0'){
r = min(r, solve(n-1, 2)+1);
r = min(r, solve(n-1, 5)+2);
}else{
r = min(r, solve(n-1, 3)+1);
r = min(r, solve(n-1, 4)+2);
}
break;
case 1:
if(a[n-1] == b[n-1]){
r = min(r, solve(n-1, 0));
}else{
r = min(r, solve(n-1, 1));
}
if(b[n-1] == '0'){
r = min(r, solve(n-1, 2)+1);
r = min(r, solve(n-1, 5)+2);
}else{
r = min(r, solve(n-1, 3)+1);
r = min(r, solve(n-1, 4)+2);
}
break;
case 2:
if(a[n-1] == b[n-1]){
r = min(r, solve(n-1, 0));
}else{
r = min(r, solve(n-1, 1) + 1);
}
if(b[n-1] == '0'){
r = min(r, solve(n-1, 2));
r = min(r, solve(n-1, 5)+2);
}else{
r = min(r, solve(n-1, 3)+1);
r = min(r, solve(n-1, 4)+1);
}
break;
case 3:
if(a[n-1] == b[n-1]){
r = min(r, solve(n-1, 0));
}else{
r = min(r, solve(n-1, 1) + 1);
}
if(b[n-1] == '0'){
r = min(r, solve(n-1, 2)+1);
r = min(r, solve(n-1, 5)+1);
}else{
r = min(r, solve(n-1, 3));
r = min(r, solve(n-1, 4)+2);
}
break;
case 4:
if(a[n-1] == b[n-1]){
r = min(r, solve(n-1, 0));
}else{
r = min(r, solve(n-1, 1));
}
if(b[n-1] == '0'){
r = min(r, solve(n-1, 2));
r = min(r, solve(n-1, 5)+1);
}else{
r = min(r, solve(n-1, 3)+1);
r = min(r, solve(n-1, 4));
}
break;
case 5:
if(a[n-1] == b[n-1]){
r = min(r, solve(n-1, 0));
}else{
r = min(r, solve(n-1, 1));
}
if(b[n-1] == '0'){
r = min(r, solve(n-1, 2)+1);
r = min(r, solve(n-1, 5));
}else{
r = min(r, solve(n-1, 3));
r = min(r, solve(n-1, 4)+1);
}
break;
}
}
return r;
}
int main(){
for(int i=0;i<MAXN;++i) for(int j=0;j<6;++j) dp[i][j] = -1;
scanf("%d", &n);
scanf("%s", a);
scanf("%s", b);
printf("%d\n", solve(n, 0));
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:116:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
lamp.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", a);
~~~~~^~~~~~~~~
lamp.cpp:118:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", b);
~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23808 KB |
Output is correct |
4 |
Correct |
20 ms |
23808 KB |
Output is correct |
5 |
Correct |
22 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
20 ms |
23808 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
20 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
20 ms |
23936 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
18 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
19 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23808 KB |
Output is correct |
20 |
Correct |
19 ms |
23808 KB |
Output is correct |
21 |
Correct |
19 ms |
23808 KB |
Output is correct |
22 |
Correct |
19 ms |
23808 KB |
Output is correct |
23 |
Correct |
19 ms |
23808 KB |
Output is correct |
24 |
Correct |
19 ms |
23808 KB |
Output is correct |
25 |
Correct |
19 ms |
23808 KB |
Output is correct |
26 |
Incorrect |
18 ms |
23808 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23808 KB |
Output is correct |
4 |
Correct |
20 ms |
23808 KB |
Output is correct |
5 |
Correct |
22 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
20 ms |
23808 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
20 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
20 ms |
23936 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
18 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
19 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23808 KB |
Output is correct |
20 |
Correct |
19 ms |
23808 KB |
Output is correct |
21 |
Correct |
19 ms |
23808 KB |
Output is correct |
22 |
Correct |
19 ms |
23808 KB |
Output is correct |
23 |
Correct |
19 ms |
23808 KB |
Output is correct |
24 |
Correct |
19 ms |
23808 KB |
Output is correct |
25 |
Correct |
19 ms |
23808 KB |
Output is correct |
26 |
Incorrect |
18 ms |
23808 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
20 ms |
23808 KB |
Output is correct |
6 |
Correct |
20 ms |
23808 KB |
Output is correct |
7 |
Correct |
106 ms |
59000 KB |
Output is correct |
8 |
Correct |
106 ms |
59100 KB |
Output is correct |
9 |
Correct |
112 ms |
59000 KB |
Output is correct |
10 |
Correct |
137 ms |
59000 KB |
Output is correct |
11 |
Correct |
99 ms |
59000 KB |
Output is correct |
12 |
Correct |
97 ms |
59000 KB |
Output is correct |
13 |
Correct |
99 ms |
59000 KB |
Output is correct |
14 |
Correct |
103 ms |
59128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23808 KB |
Output is correct |
4 |
Correct |
20 ms |
23808 KB |
Output is correct |
5 |
Correct |
22 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
20 ms |
23808 KB |
Output is correct |
8 |
Correct |
20 ms |
23808 KB |
Output is correct |
9 |
Correct |
18 ms |
23808 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
18 ms |
23808 KB |
Output is correct |
12 |
Correct |
20 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
20 ms |
23936 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
18 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
19 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23808 KB |
Output is correct |
20 |
Correct |
19 ms |
23808 KB |
Output is correct |
21 |
Correct |
19 ms |
23808 KB |
Output is correct |
22 |
Correct |
19 ms |
23808 KB |
Output is correct |
23 |
Correct |
19 ms |
23808 KB |
Output is correct |
24 |
Correct |
19 ms |
23808 KB |
Output is correct |
25 |
Correct |
19 ms |
23808 KB |
Output is correct |
26 |
Incorrect |
18 ms |
23808 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |