#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
int get(int x,int op) {
if(op == 0) return 0;
if(op == 1) return 1;
if(op == 2) return x ^ 1;
return x;
}
int op(int a) {
return a != 3;
}
int op(int a,int b) {
return (a != 3) + (b != 3);
}
int main() {
int n;
cin >> n;
int dp[n + 1][4][4][2] = {};
int a[n + 1];
int b[n + 1];
for(int i = 1; i <= n; i++) {
char c;
cin >> c;
c -= '0';
a[i] = c;
}
for(int i = 1; i <= n; i++) {
char c;
cin >> c;
c -= '0';
b[i] = c;
}
int lm0 = inf;
int lm1 = inf;
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
int x = get(a[1],i);
int y = get(x,j);
if(y == b[1]) {
dp[1][i][j][0] = op(i,j);
dp[1][i][j][1] = inf;
}
else {
dp[1][i][j][1] = op(i,j) + 1;
dp[1][i][j][0] = inf;
}
lm0 = min(lm0,dp[1][i][j][0]);
lm1 = min(lm1,dp[1][i][j][1]);
}
}
for(int i = 2; i <= n; i++) {
int cm0 = inf,cm1 = inf;
for(int j = 0; j < 4; j++) {
for(int k = 0; k < 4; k++) {
int x = get(a[i],j);
int y = get(x,k);
if(y != b[i]) {
dp[i][j][k][0] = inf;
int &r = dp[i][j][k][1];
r = dp[i - 1][j][k][1];
r = min(r,lm1 + op(j,k));
for(int x = 0; x < 4; x++) r = min(r,min(dp[i - 1][x][j][0] + 1,dp[i - 1][x][j][1]) + op(k));
for(int x = 0; x < 4; x++) r = min(r,min(dp[i - 1][j][x][0] + 1,dp[i - 1][j][x][1]) + op(k));
cm1 = min(cm1,dp[i][j][k][1]);
}
else {
dp[i][j][k][1] = inf;
int &r = dp[i][j][k][0];
r = dp[i - 1][j][k][0];
r = min(r,min(lm0,lm1) + op(j,k));
for(int x = 0; x < 4; x++) r = min(r,min(dp[i - 1][x][j][0],dp[i - 1][x][j][1]) + op(k));
for(int x = 0; x < 4; x++) r = min(r,min(dp[i - 1][j][x][0],dp[i - 1][j][x][1]) + op(k));
cm0 = min(cm0,dp[i][j][k][0]);
}
}
}
lm0 = cm0;
lm1 = cm1;
}
cout<<min(lm0,lm1)<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
380 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
0 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
0 ms |
364 KB |
Output is correct |
25 |
Correct |
0 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
372 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
380 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
0 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
0 ms |
364 KB |
Output is correct |
25 |
Correct |
0 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
372 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
2 ms |
620 KB |
Output is correct |
37 |
Correct |
1 ms |
620 KB |
Output is correct |
38 |
Correct |
2 ms |
620 KB |
Output is correct |
39 |
Correct |
1 ms |
620 KB |
Output is correct |
40 |
Correct |
1 ms |
620 KB |
Output is correct |
41 |
Correct |
2 ms |
620 KB |
Output is correct |
42 |
Correct |
1 ms |
620 KB |
Output is correct |
43 |
Correct |
1 ms |
620 KB |
Output is correct |
44 |
Correct |
1 ms |
620 KB |
Output is correct |
45 |
Correct |
1 ms |
620 KB |
Output is correct |
46 |
Correct |
1 ms |
620 KB |
Output is correct |
47 |
Correct |
1 ms |
620 KB |
Output is correct |
48 |
Correct |
1 ms |
620 KB |
Output is correct |
49 |
Correct |
1 ms |
620 KB |
Output is correct |
50 |
Correct |
1 ms |
620 KB |
Output is correct |
51 |
Correct |
1 ms |
620 KB |
Output is correct |
52 |
Correct |
2 ms |
620 KB |
Output is correct |
53 |
Correct |
1 ms |
620 KB |
Output is correct |
54 |
Correct |
2 ms |
620 KB |
Output is correct |
55 |
Correct |
2 ms |
620 KB |
Output is correct |
56 |
Correct |
3 ms |
620 KB |
Output is correct |
57 |
Correct |
1 ms |
620 KB |
Output is correct |
58 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
429 ms |
133432 KB |
Output is correct |
8 |
Correct |
437 ms |
133356 KB |
Output is correct |
9 |
Correct |
442 ms |
133800 KB |
Output is correct |
10 |
Correct |
448 ms |
133868 KB |
Output is correct |
11 |
Correct |
433 ms |
133740 KB |
Output is correct |
12 |
Correct |
430 ms |
133612 KB |
Output is correct |
13 |
Correct |
442 ms |
133740 KB |
Output is correct |
14 |
Correct |
432 ms |
133740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
380 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
0 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
0 ms |
364 KB |
Output is correct |
25 |
Correct |
0 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
372 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
2 ms |
620 KB |
Output is correct |
37 |
Correct |
1 ms |
620 KB |
Output is correct |
38 |
Correct |
2 ms |
620 KB |
Output is correct |
39 |
Correct |
1 ms |
620 KB |
Output is correct |
40 |
Correct |
1 ms |
620 KB |
Output is correct |
41 |
Correct |
2 ms |
620 KB |
Output is correct |
42 |
Correct |
1 ms |
620 KB |
Output is correct |
43 |
Correct |
1 ms |
620 KB |
Output is correct |
44 |
Correct |
1 ms |
620 KB |
Output is correct |
45 |
Correct |
1 ms |
620 KB |
Output is correct |
46 |
Correct |
1 ms |
620 KB |
Output is correct |
47 |
Correct |
1 ms |
620 KB |
Output is correct |
48 |
Correct |
1 ms |
620 KB |
Output is correct |
49 |
Correct |
1 ms |
620 KB |
Output is correct |
50 |
Correct |
1 ms |
620 KB |
Output is correct |
51 |
Correct |
1 ms |
620 KB |
Output is correct |
52 |
Correct |
2 ms |
620 KB |
Output is correct |
53 |
Correct |
1 ms |
620 KB |
Output is correct |
54 |
Correct |
2 ms |
620 KB |
Output is correct |
55 |
Correct |
2 ms |
620 KB |
Output is correct |
56 |
Correct |
3 ms |
620 KB |
Output is correct |
57 |
Correct |
1 ms |
620 KB |
Output is correct |
58 |
Correct |
1 ms |
620 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
384 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
0 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
429 ms |
133432 KB |
Output is correct |
66 |
Correct |
437 ms |
133356 KB |
Output is correct |
67 |
Correct |
442 ms |
133800 KB |
Output is correct |
68 |
Correct |
448 ms |
133868 KB |
Output is correct |
69 |
Correct |
433 ms |
133740 KB |
Output is correct |
70 |
Correct |
430 ms |
133612 KB |
Output is correct |
71 |
Correct |
442 ms |
133740 KB |
Output is correct |
72 |
Correct |
432 ms |
133740 KB |
Output is correct |
73 |
Correct |
462 ms |
135572 KB |
Output is correct |
74 |
Correct |
438 ms |
135636 KB |
Output is correct |
75 |
Correct |
429 ms |
135276 KB |
Output is correct |
76 |
Correct |
436 ms |
135404 KB |
Output is correct |
77 |
Correct |
435 ms |
135276 KB |
Output is correct |
78 |
Correct |
433 ms |
135340 KB |
Output is correct |
79 |
Correct |
438 ms |
135276 KB |
Output is correct |
80 |
Correct |
437 ms |
135288 KB |
Output is correct |
81 |
Correct |
437 ms |
135404 KB |
Output is correct |
82 |
Correct |
428 ms |
135404 KB |
Output is correct |
83 |
Correct |
455 ms |
135404 KB |
Output is correct |
84 |
Correct |
447 ms |
135276 KB |
Output is correct |
85 |
Correct |
446 ms |
135276 KB |
Output is correct |
86 |
Correct |
450 ms |
135276 KB |
Output is correct |
87 |
Correct |
446 ms |
135404 KB |
Output is correct |
88 |
Correct |
478 ms |
135404 KB |
Output is correct |
89 |
Correct |
465 ms |
135532 KB |
Output is correct |
90 |
Correct |
447 ms |
135276 KB |
Output is correct |
91 |
Correct |
455 ms |
135404 KB |
Output is correct |
92 |
Correct |
454 ms |
135276 KB |
Output is correct |
93 |
Correct |
457 ms |
135276 KB |
Output is correct |
94 |
Correct |
461 ms |
135404 KB |
Output is correct |
95 |
Correct |
450 ms |
135276 KB |
Output is correct |
96 |
Correct |
455 ms |
135276 KB |
Output is correct |
97 |
Correct |
462 ms |
135276 KB |
Output is correct |
98 |
Correct |
462 ms |
135404 KB |
Output is correct |
99 |
Correct |
453 ms |
135276 KB |
Output is correct |
100 |
Correct |
455 ms |
135436 KB |
Output is correct |
101 |
Correct |
460 ms |
135276 KB |
Output is correct |
102 |
Correct |
454 ms |
135276 KB |
Output is correct |