#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;
if(n!=0){
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:118:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
lamp.cpp:119:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", a);
~~~~~^~~~~~~~~
lamp.cpp:120: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 |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
19 ms |
23808 KB |
Output is correct |
8 |
Correct |
19 ms |
23808 KB |
Output is correct |
9 |
Correct |
19 ms |
23808 KB |
Output is correct |
10 |
Correct |
20 ms |
23808 KB |
Output is correct |
11 |
Correct |
20 ms |
23808 KB |
Output is correct |
12 |
Correct |
19 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
20 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
24 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 |
21 ms |
23808 KB |
Output is correct |
26 |
Incorrect |
19 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 |
20 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
19 ms |
23808 KB |
Output is correct |
8 |
Correct |
19 ms |
23808 KB |
Output is correct |
9 |
Correct |
19 ms |
23808 KB |
Output is correct |
10 |
Correct |
20 ms |
23808 KB |
Output is correct |
11 |
Correct |
20 ms |
23808 KB |
Output is correct |
12 |
Correct |
19 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
20 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
24 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 |
21 ms |
23808 KB |
Output is correct |
26 |
Incorrect |
19 ms |
23808 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23840 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 |
19 ms |
23808 KB |
Output is correct |
7 |
Correct |
101 ms |
57080 KB |
Output is correct |
8 |
Correct |
100 ms |
57080 KB |
Output is correct |
9 |
Correct |
98 ms |
57084 KB |
Output is correct |
10 |
Correct |
97 ms |
57080 KB |
Output is correct |
11 |
Correct |
99 ms |
57080 KB |
Output is correct |
12 |
Correct |
96 ms |
57084 KB |
Output is correct |
13 |
Correct |
98 ms |
57084 KB |
Output is correct |
14 |
Correct |
97 ms |
57080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
20 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
18 ms |
23808 KB |
Output is correct |
7 |
Correct |
19 ms |
23808 KB |
Output is correct |
8 |
Correct |
19 ms |
23808 KB |
Output is correct |
9 |
Correct |
19 ms |
23808 KB |
Output is correct |
10 |
Correct |
20 ms |
23808 KB |
Output is correct |
11 |
Correct |
20 ms |
23808 KB |
Output is correct |
12 |
Correct |
19 ms |
23808 KB |
Output is correct |
13 |
Correct |
19 ms |
23808 KB |
Output is correct |
14 |
Correct |
20 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
19 ms |
23808 KB |
Output is correct |
17 |
Correct |
24 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 |
21 ms |
23808 KB |
Output is correct |
26 |
Incorrect |
19 ms |
23808 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |