#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=1e6;
int n, dp[mxN][5]; // use nothing, use 0 parity 1, use 0 parity 0, use 1 parity 1, use 1 parity 0
string a, b;
bool ck(int i, int t) {
char x=t==0?a[i]:t<=2?'0':'1';
return x!=b[i];
}
bool bad(int i, int j, int k) {
return ck(i, j)&&!ck(i-1, k);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
memset(dp, 0x3f, sizeof(dp));
dp[0][0]=(a[0]!=b[0]);
dp[0][1]=1+(b[0]=='1');
dp[0][3]=1+(b[0]=='0');
for (int i=1; i<n; ++i) {
dp[i][0]=min(dp[i][0], dp[i-1][0]+bad(i, 0, 0));
dp[i][1]=min(dp[i][1], dp[i-1][0]+bad(i, 1, 0)+1);
dp[i][3]=min(dp[i][3], dp[i-1][0]+bad(i, 3, 0)+1);
for (int j=1; j<5; ++j) {
dp[i][j]=min(dp[i][j], dp[i-1][j]+bad(i, j, j));
dp[i][0]=min(dp[i][0], dp[i-1][j]+bad(i, 0, j));
dp[i][5-j]=min(dp[i][5-j], dp[i-1][j]+bad(i, 5-j, j)+(j%2));
}
}
cout << *min_element(dp[n-1], dp[n-1]+5);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
19796 KB |
Output is correct |
2 |
Correct |
8 ms |
19784 KB |
Output is correct |
3 |
Correct |
8 ms |
19796 KB |
Output is correct |
4 |
Correct |
8 ms |
19796 KB |
Output is correct |
5 |
Correct |
7 ms |
19784 KB |
Output is correct |
6 |
Correct |
9 ms |
19796 KB |
Output is correct |
7 |
Correct |
8 ms |
19836 KB |
Output is correct |
8 |
Correct |
8 ms |
19780 KB |
Output is correct |
9 |
Correct |
8 ms |
19796 KB |
Output is correct |
10 |
Correct |
8 ms |
19796 KB |
Output is correct |
11 |
Correct |
8 ms |
19796 KB |
Output is correct |
12 |
Correct |
8 ms |
19796 KB |
Output is correct |
13 |
Correct |
10 ms |
19796 KB |
Output is correct |
14 |
Correct |
9 ms |
19796 KB |
Output is correct |
15 |
Correct |
8 ms |
19796 KB |
Output is correct |
16 |
Correct |
8 ms |
19796 KB |
Output is correct |
17 |
Correct |
8 ms |
19796 KB |
Output is correct |
18 |
Correct |
8 ms |
19796 KB |
Output is correct |
19 |
Correct |
8 ms |
19796 KB |
Output is correct |
20 |
Correct |
7 ms |
19892 KB |
Output is correct |
21 |
Correct |
8 ms |
19796 KB |
Output is correct |
22 |
Correct |
7 ms |
19796 KB |
Output is correct |
23 |
Correct |
8 ms |
19792 KB |
Output is correct |
24 |
Correct |
8 ms |
19796 KB |
Output is correct |
25 |
Correct |
10 ms |
19896 KB |
Output is correct |
26 |
Correct |
8 ms |
19796 KB |
Output is correct |
27 |
Correct |
8 ms |
19784 KB |
Output is correct |
28 |
Correct |
8 ms |
19840 KB |
Output is correct |
29 |
Correct |
8 ms |
19796 KB |
Output is correct |
30 |
Correct |
9 ms |
19784 KB |
Output is correct |
31 |
Correct |
9 ms |
19780 KB |
Output is correct |
32 |
Correct |
8 ms |
19872 KB |
Output is correct |
33 |
Correct |
8 ms |
19784 KB |
Output is correct |
34 |
Correct |
8 ms |
19796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
19796 KB |
Output is correct |
2 |
Correct |
8 ms |
19784 KB |
Output is correct |
3 |
Correct |
8 ms |
19796 KB |
Output is correct |
4 |
Correct |
8 ms |
19796 KB |
Output is correct |
5 |
Correct |
7 ms |
19784 KB |
Output is correct |
6 |
Correct |
9 ms |
19796 KB |
Output is correct |
7 |
Correct |
8 ms |
19836 KB |
Output is correct |
8 |
Correct |
8 ms |
19780 KB |
Output is correct |
9 |
Correct |
8 ms |
19796 KB |
Output is correct |
10 |
Correct |
8 ms |
19796 KB |
Output is correct |
11 |
Correct |
8 ms |
19796 KB |
Output is correct |
12 |
Correct |
8 ms |
19796 KB |
Output is correct |
13 |
Correct |
10 ms |
19796 KB |
Output is correct |
14 |
Correct |
9 ms |
19796 KB |
Output is correct |
15 |
Correct |
8 ms |
19796 KB |
Output is correct |
16 |
Correct |
8 ms |
19796 KB |
Output is correct |
17 |
Correct |
8 ms |
19796 KB |
Output is correct |
18 |
Correct |
8 ms |
19796 KB |
Output is correct |
19 |
Correct |
8 ms |
19796 KB |
Output is correct |
20 |
Correct |
7 ms |
19892 KB |
Output is correct |
21 |
Correct |
8 ms |
19796 KB |
Output is correct |
22 |
Correct |
7 ms |
19796 KB |
Output is correct |
23 |
Correct |
8 ms |
19792 KB |
Output is correct |
24 |
Correct |
8 ms |
19796 KB |
Output is correct |
25 |
Correct |
10 ms |
19896 KB |
Output is correct |
26 |
Correct |
8 ms |
19796 KB |
Output is correct |
27 |
Correct |
8 ms |
19784 KB |
Output is correct |
28 |
Correct |
8 ms |
19840 KB |
Output is correct |
29 |
Correct |
8 ms |
19796 KB |
Output is correct |
30 |
Correct |
9 ms |
19784 KB |
Output is correct |
31 |
Correct |
9 ms |
19780 KB |
Output is correct |
32 |
Correct |
8 ms |
19872 KB |
Output is correct |
33 |
Correct |
8 ms |
19784 KB |
Output is correct |
34 |
Correct |
8 ms |
19796 KB |
Output is correct |
35 |
Correct |
7 ms |
19784 KB |
Output is correct |
36 |
Correct |
8 ms |
19896 KB |
Output is correct |
37 |
Correct |
8 ms |
19788 KB |
Output is correct |
38 |
Correct |
8 ms |
19860 KB |
Output is correct |
39 |
Correct |
8 ms |
19784 KB |
Output is correct |
40 |
Correct |
9 ms |
19796 KB |
Output is correct |
41 |
Correct |
8 ms |
19884 KB |
Output is correct |
42 |
Correct |
8 ms |
19796 KB |
Output is correct |
43 |
Correct |
10 ms |
19808 KB |
Output is correct |
44 |
Correct |
8 ms |
19836 KB |
Output is correct |
45 |
Correct |
8 ms |
19784 KB |
Output is correct |
46 |
Correct |
9 ms |
19796 KB |
Output is correct |
47 |
Correct |
8 ms |
19796 KB |
Output is correct |
48 |
Correct |
8 ms |
19796 KB |
Output is correct |
49 |
Correct |
8 ms |
19796 KB |
Output is correct |
50 |
Correct |
8 ms |
19796 KB |
Output is correct |
51 |
Correct |
8 ms |
19796 KB |
Output is correct |
52 |
Correct |
8 ms |
19796 KB |
Output is correct |
53 |
Correct |
8 ms |
19796 KB |
Output is correct |
54 |
Correct |
8 ms |
19796 KB |
Output is correct |
55 |
Correct |
8 ms |
19796 KB |
Output is correct |
56 |
Correct |
7 ms |
19796 KB |
Output is correct |
57 |
Correct |
8 ms |
19784 KB |
Output is correct |
58 |
Correct |
8 ms |
19792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
19784 KB |
Output is correct |
2 |
Correct |
8 ms |
19796 KB |
Output is correct |
3 |
Correct |
7 ms |
19796 KB |
Output is correct |
4 |
Correct |
8 ms |
19872 KB |
Output is correct |
5 |
Correct |
8 ms |
19796 KB |
Output is correct |
6 |
Correct |
8 ms |
19796 KB |
Output is correct |
7 |
Correct |
44 ms |
23692 KB |
Output is correct |
8 |
Correct |
44 ms |
23616 KB |
Output is correct |
9 |
Correct |
47 ms |
23644 KB |
Output is correct |
10 |
Correct |
45 ms |
23560 KB |
Output is correct |
11 |
Correct |
43 ms |
23644 KB |
Output is correct |
12 |
Correct |
43 ms |
23636 KB |
Output is correct |
13 |
Correct |
42 ms |
23524 KB |
Output is correct |
14 |
Correct |
43 ms |
23532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
19796 KB |
Output is correct |
2 |
Correct |
8 ms |
19784 KB |
Output is correct |
3 |
Correct |
8 ms |
19796 KB |
Output is correct |
4 |
Correct |
8 ms |
19796 KB |
Output is correct |
5 |
Correct |
7 ms |
19784 KB |
Output is correct |
6 |
Correct |
9 ms |
19796 KB |
Output is correct |
7 |
Correct |
8 ms |
19836 KB |
Output is correct |
8 |
Correct |
8 ms |
19780 KB |
Output is correct |
9 |
Correct |
8 ms |
19796 KB |
Output is correct |
10 |
Correct |
8 ms |
19796 KB |
Output is correct |
11 |
Correct |
8 ms |
19796 KB |
Output is correct |
12 |
Correct |
8 ms |
19796 KB |
Output is correct |
13 |
Correct |
10 ms |
19796 KB |
Output is correct |
14 |
Correct |
9 ms |
19796 KB |
Output is correct |
15 |
Correct |
8 ms |
19796 KB |
Output is correct |
16 |
Correct |
8 ms |
19796 KB |
Output is correct |
17 |
Correct |
8 ms |
19796 KB |
Output is correct |
18 |
Correct |
8 ms |
19796 KB |
Output is correct |
19 |
Correct |
8 ms |
19796 KB |
Output is correct |
20 |
Correct |
7 ms |
19892 KB |
Output is correct |
21 |
Correct |
8 ms |
19796 KB |
Output is correct |
22 |
Correct |
7 ms |
19796 KB |
Output is correct |
23 |
Correct |
8 ms |
19792 KB |
Output is correct |
24 |
Correct |
8 ms |
19796 KB |
Output is correct |
25 |
Correct |
10 ms |
19896 KB |
Output is correct |
26 |
Correct |
8 ms |
19796 KB |
Output is correct |
27 |
Correct |
8 ms |
19784 KB |
Output is correct |
28 |
Correct |
8 ms |
19840 KB |
Output is correct |
29 |
Correct |
8 ms |
19796 KB |
Output is correct |
30 |
Correct |
9 ms |
19784 KB |
Output is correct |
31 |
Correct |
9 ms |
19780 KB |
Output is correct |
32 |
Correct |
8 ms |
19872 KB |
Output is correct |
33 |
Correct |
8 ms |
19784 KB |
Output is correct |
34 |
Correct |
8 ms |
19796 KB |
Output is correct |
35 |
Correct |
7 ms |
19784 KB |
Output is correct |
36 |
Correct |
8 ms |
19896 KB |
Output is correct |
37 |
Correct |
8 ms |
19788 KB |
Output is correct |
38 |
Correct |
8 ms |
19860 KB |
Output is correct |
39 |
Correct |
8 ms |
19784 KB |
Output is correct |
40 |
Correct |
9 ms |
19796 KB |
Output is correct |
41 |
Correct |
8 ms |
19884 KB |
Output is correct |
42 |
Correct |
8 ms |
19796 KB |
Output is correct |
43 |
Correct |
10 ms |
19808 KB |
Output is correct |
44 |
Correct |
8 ms |
19836 KB |
Output is correct |
45 |
Correct |
8 ms |
19784 KB |
Output is correct |
46 |
Correct |
9 ms |
19796 KB |
Output is correct |
47 |
Correct |
8 ms |
19796 KB |
Output is correct |
48 |
Correct |
8 ms |
19796 KB |
Output is correct |
49 |
Correct |
8 ms |
19796 KB |
Output is correct |
50 |
Correct |
8 ms |
19796 KB |
Output is correct |
51 |
Correct |
8 ms |
19796 KB |
Output is correct |
52 |
Correct |
8 ms |
19796 KB |
Output is correct |
53 |
Correct |
8 ms |
19796 KB |
Output is correct |
54 |
Correct |
8 ms |
19796 KB |
Output is correct |
55 |
Correct |
8 ms |
19796 KB |
Output is correct |
56 |
Correct |
7 ms |
19796 KB |
Output is correct |
57 |
Correct |
8 ms |
19784 KB |
Output is correct |
58 |
Correct |
8 ms |
19792 KB |
Output is correct |
59 |
Correct |
8 ms |
19784 KB |
Output is correct |
60 |
Correct |
8 ms |
19796 KB |
Output is correct |
61 |
Correct |
7 ms |
19796 KB |
Output is correct |
62 |
Correct |
8 ms |
19872 KB |
Output is correct |
63 |
Correct |
8 ms |
19796 KB |
Output is correct |
64 |
Correct |
8 ms |
19796 KB |
Output is correct |
65 |
Correct |
44 ms |
23692 KB |
Output is correct |
66 |
Correct |
44 ms |
23616 KB |
Output is correct |
67 |
Correct |
47 ms |
23644 KB |
Output is correct |
68 |
Correct |
45 ms |
23560 KB |
Output is correct |
69 |
Correct |
43 ms |
23644 KB |
Output is correct |
70 |
Correct |
43 ms |
23636 KB |
Output is correct |
71 |
Correct |
42 ms |
23524 KB |
Output is correct |
72 |
Correct |
43 ms |
23532 KB |
Output is correct |
73 |
Correct |
41 ms |
23568 KB |
Output is correct |
74 |
Correct |
43 ms |
23612 KB |
Output is correct |
75 |
Correct |
42 ms |
23580 KB |
Output is correct |
76 |
Correct |
42 ms |
23640 KB |
Output is correct |
77 |
Correct |
45 ms |
23584 KB |
Output is correct |
78 |
Correct |
44 ms |
23640 KB |
Output is correct |
79 |
Correct |
42 ms |
23604 KB |
Output is correct |
80 |
Correct |
46 ms |
23584 KB |
Output is correct |
81 |
Correct |
46 ms |
23580 KB |
Output is correct |
82 |
Correct |
43 ms |
23632 KB |
Output is correct |
83 |
Correct |
47 ms |
23620 KB |
Output is correct |
84 |
Correct |
54 ms |
23720 KB |
Output is correct |
85 |
Correct |
50 ms |
23556 KB |
Output is correct |
86 |
Correct |
46 ms |
23596 KB |
Output is correct |
87 |
Correct |
48 ms |
23636 KB |
Output is correct |
88 |
Correct |
48 ms |
23688 KB |
Output is correct |
89 |
Correct |
46 ms |
23628 KB |
Output is correct |
90 |
Correct |
52 ms |
23584 KB |
Output is correct |
91 |
Correct |
52 ms |
23604 KB |
Output is correct |
92 |
Correct |
54 ms |
23580 KB |
Output is correct |
93 |
Correct |
51 ms |
23636 KB |
Output is correct |
94 |
Correct |
51 ms |
23708 KB |
Output is correct |
95 |
Correct |
51 ms |
23576 KB |
Output is correct |
96 |
Correct |
53 ms |
23692 KB |
Output is correct |
97 |
Correct |
51 ms |
23608 KB |
Output is correct |
98 |
Correct |
52 ms |
23584 KB |
Output is correct |
99 |
Correct |
52 ms |
23556 KB |
Output is correct |
100 |
Correct |
51 ms |
23668 KB |
Output is correct |
101 |
Correct |
52 ms |
23616 KB |
Output is correct |
102 |
Correct |
53 ms |
23584 KB |
Output is correct |