#include <bits/stdc++.h>
#define fi first
#define se second
const int N = 1000010;
using namespace std;
int n;
int A[N], B[N], C[N], D[N];
char a[N], b[N];
int d[N][3][2];
void upd(int &x, int y)
{
x = min(x, y);
}
int main()
{
ios_base::sync_with_stdio(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
int inf = 1e9;
for(int i = 0; i < N; i++){
for(int j = 0; j < 3; j++){
for(int h = 0; h < 2; h++){
d[i][j][h] = inf;
}
}
}
d[0][0][0] = 0;
for(int i = 1; i <= n; i++){
for(int g1 = 0; g1 < 3; g1++){
for(int g2 = 0; g2 < 2; g2++){
upd(d[i][g1][g2], d[i - 1][g1][g2]);
upd(d[i][0][g2], d[i - 1][g1][g2]);
upd(d[i][g1][0], d[i - 1][g1][g2]);
upd(d[i][0][0], d[i - 1][g1][g2]);
if(g1 == 0){
upd(d[i][1][g2], d[i - 1][g1][g2] + 1);
upd(d[i][2][g2], d[i - 1][g1][g2] + 1);
if(g2 == 0){
upd(d[i][1][1], d[i - 1][g1][g2] + 2);
upd(d[i][2][1], d[i - 1][g1][g2] + 2);
}
}
if(g2 == 0){
upd(d[i][g1][1], d[i - 1][g1][g2] + 1);
}
}
}
for(int g1 = 0; g1 < 3; g1++){
for(int g2 = 0; g2 < 2; g2++){
int cur = a[i] - '0', need = b[i] - '0';
if(g1 == 1) cur = 1;
else if(g1 == 2) cur = 0;
if(g2 == 1) cur ^= 1;
if(cur != need){
d[i][g1][g2] = inf;
}
}
}
}
int res = inf;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 2; j++){
res = min(res, d[n][i][j]);
}
}
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23808 KB |
Output is correct |
2 |
Correct |
13 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
16 ms |
23808 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
23804 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
11 |
Correct |
16 ms |
23824 KB |
Output is correct |
12 |
Correct |
14 ms |
23812 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
16 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
15 ms |
23808 KB |
Output is correct |
18 |
Correct |
14 ms |
23808 KB |
Output is correct |
19 |
Correct |
14 ms |
23808 KB |
Output is correct |
20 |
Correct |
14 ms |
23808 KB |
Output is correct |
21 |
Correct |
14 ms |
23808 KB |
Output is correct |
22 |
Correct |
14 ms |
23808 KB |
Output is correct |
23 |
Correct |
14 ms |
23808 KB |
Output is correct |
24 |
Correct |
13 ms |
23808 KB |
Output is correct |
25 |
Correct |
13 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
12 ms |
23808 KB |
Output is correct |
28 |
Correct |
13 ms |
23808 KB |
Output is correct |
29 |
Correct |
13 ms |
23808 KB |
Output is correct |
30 |
Correct |
12 ms |
23808 KB |
Output is correct |
31 |
Correct |
15 ms |
23808 KB |
Output is correct |
32 |
Correct |
12 ms |
23808 KB |
Output is correct |
33 |
Correct |
13 ms |
23808 KB |
Output is correct |
34 |
Correct |
14 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23808 KB |
Output is correct |
2 |
Correct |
13 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
16 ms |
23808 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
23804 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
11 |
Correct |
16 ms |
23824 KB |
Output is correct |
12 |
Correct |
14 ms |
23812 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
16 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
15 ms |
23808 KB |
Output is correct |
18 |
Correct |
14 ms |
23808 KB |
Output is correct |
19 |
Correct |
14 ms |
23808 KB |
Output is correct |
20 |
Correct |
14 ms |
23808 KB |
Output is correct |
21 |
Correct |
14 ms |
23808 KB |
Output is correct |
22 |
Correct |
14 ms |
23808 KB |
Output is correct |
23 |
Correct |
14 ms |
23808 KB |
Output is correct |
24 |
Correct |
13 ms |
23808 KB |
Output is correct |
25 |
Correct |
13 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
12 ms |
23808 KB |
Output is correct |
28 |
Correct |
13 ms |
23808 KB |
Output is correct |
29 |
Correct |
13 ms |
23808 KB |
Output is correct |
30 |
Correct |
12 ms |
23808 KB |
Output is correct |
31 |
Correct |
15 ms |
23808 KB |
Output is correct |
32 |
Correct |
12 ms |
23808 KB |
Output is correct |
33 |
Correct |
13 ms |
23808 KB |
Output is correct |
34 |
Correct |
14 ms |
23808 KB |
Output is correct |
35 |
Correct |
13 ms |
23808 KB |
Output is correct |
36 |
Correct |
12 ms |
23808 KB |
Output is correct |
37 |
Correct |
13 ms |
23808 KB |
Output is correct |
38 |
Correct |
14 ms |
23808 KB |
Output is correct |
39 |
Correct |
18 ms |
23936 KB |
Output is correct |
40 |
Correct |
14 ms |
23808 KB |
Output is correct |
41 |
Correct |
14 ms |
23808 KB |
Output is correct |
42 |
Correct |
13 ms |
23808 KB |
Output is correct |
43 |
Correct |
16 ms |
23808 KB |
Output is correct |
44 |
Correct |
15 ms |
23808 KB |
Output is correct |
45 |
Correct |
15 ms |
23808 KB |
Output is correct |
46 |
Correct |
15 ms |
23808 KB |
Output is correct |
47 |
Correct |
15 ms |
23808 KB |
Output is correct |
48 |
Correct |
15 ms |
23808 KB |
Output is correct |
49 |
Correct |
15 ms |
23808 KB |
Output is correct |
50 |
Correct |
15 ms |
23808 KB |
Output is correct |
51 |
Correct |
15 ms |
23808 KB |
Output is correct |
52 |
Correct |
12 ms |
23808 KB |
Output is correct |
53 |
Correct |
16 ms |
23840 KB |
Output is correct |
54 |
Correct |
16 ms |
23808 KB |
Output is correct |
55 |
Correct |
15 ms |
23840 KB |
Output is correct |
56 |
Correct |
14 ms |
23808 KB |
Output is correct |
57 |
Correct |
14 ms |
23808 KB |
Output is correct |
58 |
Correct |
15 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23808 KB |
Output is correct |
2 |
Correct |
14 ms |
23808 KB |
Output is correct |
3 |
Correct |
13 ms |
23808 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23808 KB |
Output is correct |
7 |
Correct |
115 ms |
27768 KB |
Output is correct |
8 |
Correct |
95 ms |
27664 KB |
Output is correct |
9 |
Correct |
107 ms |
27768 KB |
Output is correct |
10 |
Correct |
95 ms |
27792 KB |
Output is correct |
11 |
Correct |
93 ms |
27792 KB |
Output is correct |
12 |
Correct |
101 ms |
27844 KB |
Output is correct |
13 |
Correct |
96 ms |
27768 KB |
Output is correct |
14 |
Correct |
97 ms |
27896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23808 KB |
Output is correct |
2 |
Correct |
13 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
16 ms |
23808 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
23804 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
11 |
Correct |
16 ms |
23824 KB |
Output is correct |
12 |
Correct |
14 ms |
23812 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
16 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
15 ms |
23808 KB |
Output is correct |
18 |
Correct |
14 ms |
23808 KB |
Output is correct |
19 |
Correct |
14 ms |
23808 KB |
Output is correct |
20 |
Correct |
14 ms |
23808 KB |
Output is correct |
21 |
Correct |
14 ms |
23808 KB |
Output is correct |
22 |
Correct |
14 ms |
23808 KB |
Output is correct |
23 |
Correct |
14 ms |
23808 KB |
Output is correct |
24 |
Correct |
13 ms |
23808 KB |
Output is correct |
25 |
Correct |
13 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
12 ms |
23808 KB |
Output is correct |
28 |
Correct |
13 ms |
23808 KB |
Output is correct |
29 |
Correct |
13 ms |
23808 KB |
Output is correct |
30 |
Correct |
12 ms |
23808 KB |
Output is correct |
31 |
Correct |
15 ms |
23808 KB |
Output is correct |
32 |
Correct |
12 ms |
23808 KB |
Output is correct |
33 |
Correct |
13 ms |
23808 KB |
Output is correct |
34 |
Correct |
14 ms |
23808 KB |
Output is correct |
35 |
Correct |
13 ms |
23808 KB |
Output is correct |
36 |
Correct |
12 ms |
23808 KB |
Output is correct |
37 |
Correct |
13 ms |
23808 KB |
Output is correct |
38 |
Correct |
14 ms |
23808 KB |
Output is correct |
39 |
Correct |
18 ms |
23936 KB |
Output is correct |
40 |
Correct |
14 ms |
23808 KB |
Output is correct |
41 |
Correct |
14 ms |
23808 KB |
Output is correct |
42 |
Correct |
13 ms |
23808 KB |
Output is correct |
43 |
Correct |
16 ms |
23808 KB |
Output is correct |
44 |
Correct |
15 ms |
23808 KB |
Output is correct |
45 |
Correct |
15 ms |
23808 KB |
Output is correct |
46 |
Correct |
15 ms |
23808 KB |
Output is correct |
47 |
Correct |
15 ms |
23808 KB |
Output is correct |
48 |
Correct |
15 ms |
23808 KB |
Output is correct |
49 |
Correct |
15 ms |
23808 KB |
Output is correct |
50 |
Correct |
15 ms |
23808 KB |
Output is correct |
51 |
Correct |
15 ms |
23808 KB |
Output is correct |
52 |
Correct |
12 ms |
23808 KB |
Output is correct |
53 |
Correct |
16 ms |
23840 KB |
Output is correct |
54 |
Correct |
16 ms |
23808 KB |
Output is correct |
55 |
Correct |
15 ms |
23840 KB |
Output is correct |
56 |
Correct |
14 ms |
23808 KB |
Output is correct |
57 |
Correct |
14 ms |
23808 KB |
Output is correct |
58 |
Correct |
15 ms |
23808 KB |
Output is correct |
59 |
Correct |
13 ms |
23808 KB |
Output is correct |
60 |
Correct |
14 ms |
23808 KB |
Output is correct |
61 |
Correct |
13 ms |
23808 KB |
Output is correct |
62 |
Correct |
14 ms |
23808 KB |
Output is correct |
63 |
Correct |
13 ms |
23808 KB |
Output is correct |
64 |
Correct |
16 ms |
23808 KB |
Output is correct |
65 |
Correct |
115 ms |
27768 KB |
Output is correct |
66 |
Correct |
95 ms |
27664 KB |
Output is correct |
67 |
Correct |
107 ms |
27768 KB |
Output is correct |
68 |
Correct |
95 ms |
27792 KB |
Output is correct |
69 |
Correct |
93 ms |
27792 KB |
Output is correct |
70 |
Correct |
101 ms |
27844 KB |
Output is correct |
71 |
Correct |
96 ms |
27768 KB |
Output is correct |
72 |
Correct |
97 ms |
27896 KB |
Output is correct |
73 |
Correct |
93 ms |
27772 KB |
Output is correct |
74 |
Correct |
95 ms |
27824 KB |
Output is correct |
75 |
Correct |
91 ms |
27720 KB |
Output is correct |
76 |
Correct |
91 ms |
27768 KB |
Output is correct |
77 |
Correct |
99 ms |
27808 KB |
Output is correct |
78 |
Correct |
88 ms |
27768 KB |
Output is correct |
79 |
Correct |
95 ms |
27772 KB |
Output is correct |
80 |
Correct |
93 ms |
27768 KB |
Output is correct |
81 |
Correct |
98 ms |
27772 KB |
Output is correct |
82 |
Correct |
98 ms |
27808 KB |
Output is correct |
83 |
Correct |
97 ms |
27748 KB |
Output is correct |
84 |
Correct |
99 ms |
27896 KB |
Output is correct |
85 |
Correct |
93 ms |
27768 KB |
Output is correct |
86 |
Correct |
100 ms |
27896 KB |
Output is correct |
87 |
Correct |
100 ms |
27768 KB |
Output is correct |
88 |
Correct |
101 ms |
27768 KB |
Output is correct |
89 |
Correct |
105 ms |
27772 KB |
Output is correct |
90 |
Correct |
99 ms |
27768 KB |
Output is correct |
91 |
Correct |
99 ms |
27768 KB |
Output is correct |
92 |
Correct |
101 ms |
27768 KB |
Output is correct |
93 |
Correct |
106 ms |
27768 KB |
Output is correct |
94 |
Correct |
100 ms |
27896 KB |
Output is correct |
95 |
Correct |
106 ms |
27768 KB |
Output is correct |
96 |
Correct |
102 ms |
27768 KB |
Output is correct |
97 |
Correct |
113 ms |
27768 KB |
Output is correct |
98 |
Correct |
102 ms |
27768 KB |
Output is correct |
99 |
Correct |
97 ms |
27772 KB |
Output is correct |
100 |
Correct |
102 ms |
27896 KB |
Output is correct |
101 |
Correct |
99 ms |
27852 KB |
Output is correct |
102 |
Correct |
102 ms |
27896 KB |
Output is correct |