#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
const int N = 1e6 + 10, inf = 1e8;
int dp[N][2][2][2][2];
void solve() {
int n; string a, b; cin >> n >> a >> b;
forn(I, N) forn(A, 2) forn(B, 2) forn(C, 2) forn(D, 2) dp[I][A][B][C][D] = inf;
dp[0][0][0][0][0] = 0;
a = "?" + a;
b = "?" + b;
for(int i = 1; i <= n; ++i) {
for(int prev_set_0: {0, 1}) {
for(int prev_set_1: {0, 1}) {
if(prev_set_0 && prev_set_1) continue;
for(int prev_set_xor_before: {0, 1}) {
for(int prev_set_xor_after: {0, 1}) {
if(prev_set_xor_after && prev_set_xor_before) continue;
for(int set_0: {0, 1}) {
for(int set_1: {0, 1}) {
if(set_0 && set_1) continue;
for(int set_xor_before: {0, 1}) {
for(int set_xor_after: {0, 1}) {
if(set_xor_after && prev_set_xor_before) continue;
int newmoves = 0;
if(set_0 && !prev_set_0) ++newmoves;
if(set_1 && !prev_set_1) ++newmoves;
if(set_xor_before && !prev_set_xor_before) ++newmoves;
if(set_xor_after && !prev_set_xor_after) ++newmoves;
int x = (a[i] - '0');
if(set_xor_before) x ^= 1;
if(set_0) x = 0;
if(set_1) x = 1;
if(set_xor_after) x ^= 1;
if(x != b[i] - '0') continue;
dp[i][set_0][set_1][set_xor_before][set_xor_after] =
min(dp[i][set_0][set_1][set_xor_before][set_xor_after],
dp[i - 1][prev_set_0][prev_set_1][prev_set_xor_before][prev_set_xor_after] + newmoves);
}
}
}
}
}
}
}
}
}
int ans = inf;
for(int A: {0, 1}) for(int B: {0, 1}) for(int C: {0, 1}) for(int D: {0, 1}) ans = min(ans, dp[n][A][B][C][D]);
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
62816 KB |
Output is correct |
2 |
Correct |
28 ms |
62896 KB |
Output is correct |
3 |
Correct |
28 ms |
62848 KB |
Output is correct |
4 |
Correct |
28 ms |
62796 KB |
Output is correct |
5 |
Correct |
28 ms |
62916 KB |
Output is correct |
6 |
Correct |
32 ms |
62932 KB |
Output is correct |
7 |
Correct |
29 ms |
62944 KB |
Output is correct |
8 |
Correct |
30 ms |
62932 KB |
Output is correct |
9 |
Correct |
28 ms |
62908 KB |
Output is correct |
10 |
Correct |
32 ms |
62828 KB |
Output is correct |
11 |
Correct |
29 ms |
62868 KB |
Output is correct |
12 |
Correct |
29 ms |
62836 KB |
Output is correct |
13 |
Correct |
28 ms |
62864 KB |
Output is correct |
14 |
Correct |
28 ms |
62944 KB |
Output is correct |
15 |
Correct |
28 ms |
62816 KB |
Output is correct |
16 |
Correct |
31 ms |
62936 KB |
Output is correct |
17 |
Correct |
29 ms |
62872 KB |
Output is correct |
18 |
Correct |
31 ms |
62876 KB |
Output is correct |
19 |
Correct |
35 ms |
62840 KB |
Output is correct |
20 |
Correct |
29 ms |
62912 KB |
Output is correct |
21 |
Correct |
28 ms |
62864 KB |
Output is correct |
22 |
Correct |
30 ms |
62820 KB |
Output is correct |
23 |
Correct |
29 ms |
62936 KB |
Output is correct |
24 |
Correct |
30 ms |
62924 KB |
Output is correct |
25 |
Correct |
28 ms |
62796 KB |
Output is correct |
26 |
Correct |
29 ms |
62800 KB |
Output is correct |
27 |
Correct |
30 ms |
62860 KB |
Output is correct |
28 |
Correct |
33 ms |
62932 KB |
Output is correct |
29 |
Correct |
33 ms |
62880 KB |
Output is correct |
30 |
Correct |
31 ms |
62860 KB |
Output is correct |
31 |
Correct |
30 ms |
62832 KB |
Output is correct |
32 |
Correct |
29 ms |
62852 KB |
Output is correct |
33 |
Correct |
28 ms |
62932 KB |
Output is correct |
34 |
Correct |
28 ms |
62888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
62816 KB |
Output is correct |
2 |
Correct |
28 ms |
62896 KB |
Output is correct |
3 |
Correct |
28 ms |
62848 KB |
Output is correct |
4 |
Correct |
28 ms |
62796 KB |
Output is correct |
5 |
Correct |
28 ms |
62916 KB |
Output is correct |
6 |
Correct |
32 ms |
62932 KB |
Output is correct |
7 |
Correct |
29 ms |
62944 KB |
Output is correct |
8 |
Correct |
30 ms |
62932 KB |
Output is correct |
9 |
Correct |
28 ms |
62908 KB |
Output is correct |
10 |
Correct |
32 ms |
62828 KB |
Output is correct |
11 |
Correct |
29 ms |
62868 KB |
Output is correct |
12 |
Correct |
29 ms |
62836 KB |
Output is correct |
13 |
Correct |
28 ms |
62864 KB |
Output is correct |
14 |
Correct |
28 ms |
62944 KB |
Output is correct |
15 |
Correct |
28 ms |
62816 KB |
Output is correct |
16 |
Correct |
31 ms |
62936 KB |
Output is correct |
17 |
Correct |
29 ms |
62872 KB |
Output is correct |
18 |
Correct |
31 ms |
62876 KB |
Output is correct |
19 |
Correct |
35 ms |
62840 KB |
Output is correct |
20 |
Correct |
29 ms |
62912 KB |
Output is correct |
21 |
Correct |
28 ms |
62864 KB |
Output is correct |
22 |
Correct |
30 ms |
62820 KB |
Output is correct |
23 |
Correct |
29 ms |
62936 KB |
Output is correct |
24 |
Correct |
30 ms |
62924 KB |
Output is correct |
25 |
Correct |
28 ms |
62796 KB |
Output is correct |
26 |
Correct |
29 ms |
62800 KB |
Output is correct |
27 |
Correct |
30 ms |
62860 KB |
Output is correct |
28 |
Correct |
33 ms |
62932 KB |
Output is correct |
29 |
Correct |
33 ms |
62880 KB |
Output is correct |
30 |
Correct |
31 ms |
62860 KB |
Output is correct |
31 |
Correct |
30 ms |
62832 KB |
Output is correct |
32 |
Correct |
29 ms |
62852 KB |
Output is correct |
33 |
Correct |
28 ms |
62932 KB |
Output is correct |
34 |
Correct |
28 ms |
62888 KB |
Output is correct |
35 |
Correct |
31 ms |
62912 KB |
Output is correct |
36 |
Correct |
33 ms |
62840 KB |
Output is correct |
37 |
Correct |
29 ms |
62944 KB |
Output is correct |
38 |
Correct |
31 ms |
62932 KB |
Output is correct |
39 |
Correct |
31 ms |
62892 KB |
Output is correct |
40 |
Correct |
32 ms |
62908 KB |
Output is correct |
41 |
Correct |
30 ms |
62904 KB |
Output is correct |
42 |
Correct |
30 ms |
62856 KB |
Output is correct |
43 |
Correct |
30 ms |
62832 KB |
Output is correct |
44 |
Correct |
31 ms |
62844 KB |
Output is correct |
45 |
Correct |
29 ms |
62888 KB |
Output is correct |
46 |
Correct |
30 ms |
62844 KB |
Output is correct |
47 |
Correct |
29 ms |
62932 KB |
Output is correct |
48 |
Correct |
36 ms |
62844 KB |
Output is correct |
49 |
Correct |
29 ms |
62896 KB |
Output is correct |
50 |
Correct |
30 ms |
62924 KB |
Output is correct |
51 |
Correct |
31 ms |
62928 KB |
Output is correct |
52 |
Correct |
32 ms |
62892 KB |
Output is correct |
53 |
Correct |
33 ms |
62924 KB |
Output is correct |
54 |
Correct |
32 ms |
62928 KB |
Output is correct |
55 |
Correct |
30 ms |
62840 KB |
Output is correct |
56 |
Correct |
30 ms |
62856 KB |
Output is correct |
57 |
Correct |
30 ms |
62920 KB |
Output is correct |
58 |
Correct |
30 ms |
62860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
62900 KB |
Output is correct |
2 |
Correct |
28 ms |
62864 KB |
Output is correct |
3 |
Correct |
29 ms |
62912 KB |
Output is correct |
4 |
Correct |
33 ms |
62864 KB |
Output is correct |
5 |
Correct |
34 ms |
62860 KB |
Output is correct |
6 |
Correct |
39 ms |
62860 KB |
Output is correct |
7 |
Correct |
673 ms |
65936 KB |
Output is correct |
8 |
Correct |
682 ms |
65924 KB |
Output is correct |
9 |
Correct |
675 ms |
65932 KB |
Output is correct |
10 |
Correct |
673 ms |
66028 KB |
Output is correct |
11 |
Correct |
683 ms |
65904 KB |
Output is correct |
12 |
Correct |
727 ms |
65968 KB |
Output is correct |
13 |
Correct |
686 ms |
65980 KB |
Output is correct |
14 |
Correct |
673 ms |
65948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
62816 KB |
Output is correct |
2 |
Correct |
28 ms |
62896 KB |
Output is correct |
3 |
Correct |
28 ms |
62848 KB |
Output is correct |
4 |
Correct |
28 ms |
62796 KB |
Output is correct |
5 |
Correct |
28 ms |
62916 KB |
Output is correct |
6 |
Correct |
32 ms |
62932 KB |
Output is correct |
7 |
Correct |
29 ms |
62944 KB |
Output is correct |
8 |
Correct |
30 ms |
62932 KB |
Output is correct |
9 |
Correct |
28 ms |
62908 KB |
Output is correct |
10 |
Correct |
32 ms |
62828 KB |
Output is correct |
11 |
Correct |
29 ms |
62868 KB |
Output is correct |
12 |
Correct |
29 ms |
62836 KB |
Output is correct |
13 |
Correct |
28 ms |
62864 KB |
Output is correct |
14 |
Correct |
28 ms |
62944 KB |
Output is correct |
15 |
Correct |
28 ms |
62816 KB |
Output is correct |
16 |
Correct |
31 ms |
62936 KB |
Output is correct |
17 |
Correct |
29 ms |
62872 KB |
Output is correct |
18 |
Correct |
31 ms |
62876 KB |
Output is correct |
19 |
Correct |
35 ms |
62840 KB |
Output is correct |
20 |
Correct |
29 ms |
62912 KB |
Output is correct |
21 |
Correct |
28 ms |
62864 KB |
Output is correct |
22 |
Correct |
30 ms |
62820 KB |
Output is correct |
23 |
Correct |
29 ms |
62936 KB |
Output is correct |
24 |
Correct |
30 ms |
62924 KB |
Output is correct |
25 |
Correct |
28 ms |
62796 KB |
Output is correct |
26 |
Correct |
29 ms |
62800 KB |
Output is correct |
27 |
Correct |
30 ms |
62860 KB |
Output is correct |
28 |
Correct |
33 ms |
62932 KB |
Output is correct |
29 |
Correct |
33 ms |
62880 KB |
Output is correct |
30 |
Correct |
31 ms |
62860 KB |
Output is correct |
31 |
Correct |
30 ms |
62832 KB |
Output is correct |
32 |
Correct |
29 ms |
62852 KB |
Output is correct |
33 |
Correct |
28 ms |
62932 KB |
Output is correct |
34 |
Correct |
28 ms |
62888 KB |
Output is correct |
35 |
Correct |
31 ms |
62912 KB |
Output is correct |
36 |
Correct |
33 ms |
62840 KB |
Output is correct |
37 |
Correct |
29 ms |
62944 KB |
Output is correct |
38 |
Correct |
31 ms |
62932 KB |
Output is correct |
39 |
Correct |
31 ms |
62892 KB |
Output is correct |
40 |
Correct |
32 ms |
62908 KB |
Output is correct |
41 |
Correct |
30 ms |
62904 KB |
Output is correct |
42 |
Correct |
30 ms |
62856 KB |
Output is correct |
43 |
Correct |
30 ms |
62832 KB |
Output is correct |
44 |
Correct |
31 ms |
62844 KB |
Output is correct |
45 |
Correct |
29 ms |
62888 KB |
Output is correct |
46 |
Correct |
30 ms |
62844 KB |
Output is correct |
47 |
Correct |
29 ms |
62932 KB |
Output is correct |
48 |
Correct |
36 ms |
62844 KB |
Output is correct |
49 |
Correct |
29 ms |
62896 KB |
Output is correct |
50 |
Correct |
30 ms |
62924 KB |
Output is correct |
51 |
Correct |
31 ms |
62928 KB |
Output is correct |
52 |
Correct |
32 ms |
62892 KB |
Output is correct |
53 |
Correct |
33 ms |
62924 KB |
Output is correct |
54 |
Correct |
32 ms |
62928 KB |
Output is correct |
55 |
Correct |
30 ms |
62840 KB |
Output is correct |
56 |
Correct |
30 ms |
62856 KB |
Output is correct |
57 |
Correct |
30 ms |
62920 KB |
Output is correct |
58 |
Correct |
30 ms |
62860 KB |
Output is correct |
59 |
Correct |
28 ms |
62900 KB |
Output is correct |
60 |
Correct |
28 ms |
62864 KB |
Output is correct |
61 |
Correct |
29 ms |
62912 KB |
Output is correct |
62 |
Correct |
33 ms |
62864 KB |
Output is correct |
63 |
Correct |
34 ms |
62860 KB |
Output is correct |
64 |
Correct |
39 ms |
62860 KB |
Output is correct |
65 |
Correct |
673 ms |
65936 KB |
Output is correct |
66 |
Correct |
682 ms |
65924 KB |
Output is correct |
67 |
Correct |
675 ms |
65932 KB |
Output is correct |
68 |
Correct |
673 ms |
66028 KB |
Output is correct |
69 |
Correct |
683 ms |
65904 KB |
Output is correct |
70 |
Correct |
727 ms |
65968 KB |
Output is correct |
71 |
Correct |
686 ms |
65980 KB |
Output is correct |
72 |
Correct |
673 ms |
65948 KB |
Output is correct |
73 |
Correct |
709 ms |
65944 KB |
Output is correct |
74 |
Correct |
699 ms |
65920 KB |
Output is correct |
75 |
Correct |
684 ms |
65968 KB |
Output is correct |
76 |
Correct |
678 ms |
65944 KB |
Output is correct |
77 |
Correct |
660 ms |
65968 KB |
Output is correct |
78 |
Correct |
659 ms |
65908 KB |
Output is correct |
79 |
Correct |
715 ms |
65944 KB |
Output is correct |
80 |
Correct |
689 ms |
65968 KB |
Output is correct |
81 |
Correct |
664 ms |
65968 KB |
Output is correct |
82 |
Correct |
666 ms |
66036 KB |
Output is correct |
83 |
Correct |
741 ms |
65948 KB |
Output is correct |
84 |
Correct |
696 ms |
66000 KB |
Output is correct |
85 |
Correct |
686 ms |
65932 KB |
Output is correct |
86 |
Correct |
690 ms |
65956 KB |
Output is correct |
87 |
Correct |
701 ms |
65920 KB |
Output is correct |
88 |
Correct |
692 ms |
65944 KB |
Output is correct |
89 |
Correct |
699 ms |
65956 KB |
Output is correct |
90 |
Correct |
699 ms |
65944 KB |
Output is correct |
91 |
Correct |
703 ms |
65928 KB |
Output is correct |
92 |
Correct |
699 ms |
65944 KB |
Output is correct |
93 |
Correct |
698 ms |
65956 KB |
Output is correct |
94 |
Correct |
712 ms |
65968 KB |
Output is correct |
95 |
Correct |
709 ms |
65956 KB |
Output is correct |
96 |
Correct |
702 ms |
65980 KB |
Output is correct |
97 |
Correct |
715 ms |
65944 KB |
Output is correct |
98 |
Correct |
730 ms |
65964 KB |
Output is correct |
99 |
Correct |
718 ms |
65984 KB |
Output is correct |
100 |
Correct |
702 ms |
65940 KB |
Output is correct |
101 |
Correct |
706 ms |
65912 KB |
Output is correct |
102 |
Correct |
714 ms |
65952 KB |
Output is correct |