#include <bits/stdc++.h>
using namespace std;
//#define mod 1000000007
#define mp make_pair
#define pb push_back
#define bas(x) #x << ": " << x << " "
#define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl;
#define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl;
#define inside sl<=l&&r<=sr
#define outside sr<l||r<sl
typedef long long ll;
int n;
string s, t;
int dp[1000006][16];
int g[6][6];
void mini(int& a, int b){
a = min(a, b);
}
int f(int ind, int mod){
if (ind == n) return 0;
if (dp[ind][mod] != -1) return dp[ind][mod];
//cout << "f(" << ind << ", " << mod << ")" << endl;
int ans = 10000000;
if (s[ind] == '0' && t[ind] == '0'){
mini(ans, g[mod][0] + f(ind+1, 0));
mini(ans, g[mod][1] + f(ind+1, 1));
//mini(ans, g[mod][2] + f(ind+1, 2));
//mini(ans, g[mod][3] + f(ind+1, 3));
//mini(ans, g[mod][4] + f(ind+1, 4));
mini(ans, g[mod][5] + f(ind+1, 5));
} else if (s[ind] == '1' && t[ind] == '0'){
//mini(ans, g[mod][0] + f(ind+1, 0));
mini(ans, g[mod][1] + f(ind+1, 1));
//mini(ans, g[mod][2] + f(ind+1, 2));
mini(ans, g[mod][3] + f(ind+1, 3));
//mini(ans, g[mod][4] + f(ind+1, 4));
mini(ans, g[mod][5] + f(ind+1, 5));
} else if (s[ind] == '0' && t[ind] == '1'){
//mini(ans, g[mod][0] + f(ind+1, 0));
//mini(ans, g[mod][1] + f(ind+1, 1));
mini(ans, g[mod][2] + f(ind+1, 2));
mini(ans, g[mod][3] + f(ind+1, 3));
mini(ans, g[mod][4] + f(ind+1, 4));
//mini(ans, g[mod][5] + f(ind+1, 5));
} else if (s[ind] == '1' && t[ind] == '1'){
mini(ans, g[mod][0] + f(ind+1, 0));
//mini(ans, g[mod][1] + f(ind+1, 1));
mini(ans, g[mod][2] + f(ind+1, 2));
//mini(ans, g[mod][3] + f(ind+1, 3));
mini(ans, g[mod][4] + f(ind+1, 4));
//mini(ans, g[mod][5] + f(ind+1, 5));
} else assert(0);
return dp[ind][mod] = ans;
}
int main(){
cin >> n >> s >> t;
//cout << s << " " << t << endl;
//for (int i = 0; i < 16; i++) cout << bas(g(i, 1)) << endl;
for (int i = 0; i < n; i++) for (int j = 0; j < 16; j++) dp[i][j] = -1;
g[0][0] = 0; g[0][1] = 1; g[0][2] = 1; g[0][3] = 1; g[0][4] = 2; g[0][5] = 2;
g[1][0] = 0; g[1][1] = 0; g[1][2] = 1; g[1][3] = 1; g[1][4] = 1; g[1][5] = 2;
g[2][0] = 0; g[2][1] = 1; g[2][2] = 0; g[2][3] = 1; g[2][4] = 2; g[2][5] = 1;
g[3][0] = 0; g[3][1] = 1; g[3][2] = 1; g[3][3] = 0; g[3][4] = 1; g[3][5] = 1;
g[4][0] = 0; g[4][1] = 0; g[4][2] = 1; g[4][3] = 0; g[4][4] = 0; g[4][5] = 1;
g[5][0] = 0; g[5][1] = 1; g[5][2] = 0; g[5][3] = 0; g[5][4] = 1; g[5][5] = 0;
cout << f(0, 0) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
368 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
372 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
252 KB |
Output is correct |
16 |
Correct |
2 ms |
292 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
3 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
4 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
276 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
252 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
368 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
372 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
252 KB |
Output is correct |
16 |
Correct |
2 ms |
292 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
3 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
4 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
276 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
252 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
632 KB |
Output is correct |
36 |
Correct |
2 ms |
632 KB |
Output is correct |
37 |
Correct |
3 ms |
632 KB |
Output is correct |
38 |
Correct |
3 ms |
632 KB |
Output is correct |
39 |
Correct |
3 ms |
632 KB |
Output is correct |
40 |
Correct |
3 ms |
648 KB |
Output is correct |
41 |
Correct |
3 ms |
632 KB |
Output is correct |
42 |
Correct |
3 ms |
632 KB |
Output is correct |
43 |
Correct |
3 ms |
632 KB |
Output is correct |
44 |
Correct |
3 ms |
632 KB |
Output is correct |
45 |
Correct |
2 ms |
632 KB |
Output is correct |
46 |
Correct |
3 ms |
632 KB |
Output is correct |
47 |
Correct |
3 ms |
632 KB |
Output is correct |
48 |
Correct |
3 ms |
632 KB |
Output is correct |
49 |
Correct |
3 ms |
632 KB |
Output is correct |
50 |
Correct |
3 ms |
632 KB |
Output is correct |
51 |
Correct |
3 ms |
632 KB |
Output is correct |
52 |
Correct |
3 ms |
632 KB |
Output is correct |
53 |
Correct |
3 ms |
632 KB |
Output is correct |
54 |
Correct |
3 ms |
632 KB |
Output is correct |
55 |
Correct |
2 ms |
632 KB |
Output is correct |
56 |
Correct |
2 ms |
504 KB |
Output is correct |
57 |
Correct |
2 ms |
632 KB |
Output is correct |
58 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
279 ms |
129612 KB |
Output is correct |
8 |
Correct |
278 ms |
129760 KB |
Output is correct |
9 |
Correct |
279 ms |
129636 KB |
Output is correct |
10 |
Correct |
296 ms |
129672 KB |
Output is correct |
11 |
Correct |
279 ms |
129668 KB |
Output is correct |
12 |
Correct |
278 ms |
129652 KB |
Output is correct |
13 |
Correct |
277 ms |
129784 KB |
Output is correct |
14 |
Correct |
281 ms |
129672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
368 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
372 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
252 KB |
Output is correct |
16 |
Correct |
2 ms |
292 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
3 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
4 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
276 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
252 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
632 KB |
Output is correct |
36 |
Correct |
2 ms |
632 KB |
Output is correct |
37 |
Correct |
3 ms |
632 KB |
Output is correct |
38 |
Correct |
3 ms |
632 KB |
Output is correct |
39 |
Correct |
3 ms |
632 KB |
Output is correct |
40 |
Correct |
3 ms |
648 KB |
Output is correct |
41 |
Correct |
3 ms |
632 KB |
Output is correct |
42 |
Correct |
3 ms |
632 KB |
Output is correct |
43 |
Correct |
3 ms |
632 KB |
Output is correct |
44 |
Correct |
3 ms |
632 KB |
Output is correct |
45 |
Correct |
2 ms |
632 KB |
Output is correct |
46 |
Correct |
3 ms |
632 KB |
Output is correct |
47 |
Correct |
3 ms |
632 KB |
Output is correct |
48 |
Correct |
3 ms |
632 KB |
Output is correct |
49 |
Correct |
3 ms |
632 KB |
Output is correct |
50 |
Correct |
3 ms |
632 KB |
Output is correct |
51 |
Correct |
3 ms |
632 KB |
Output is correct |
52 |
Correct |
3 ms |
632 KB |
Output is correct |
53 |
Correct |
3 ms |
632 KB |
Output is correct |
54 |
Correct |
3 ms |
632 KB |
Output is correct |
55 |
Correct |
2 ms |
632 KB |
Output is correct |
56 |
Correct |
2 ms |
504 KB |
Output is correct |
57 |
Correct |
2 ms |
632 KB |
Output is correct |
58 |
Correct |
2 ms |
504 KB |
Output is correct |
59 |
Correct |
2 ms |
376 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
2 ms |
256 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
63 |
Correct |
2 ms |
256 KB |
Output is correct |
64 |
Correct |
2 ms |
380 KB |
Output is correct |
65 |
Correct |
279 ms |
129612 KB |
Output is correct |
66 |
Correct |
278 ms |
129760 KB |
Output is correct |
67 |
Correct |
279 ms |
129636 KB |
Output is correct |
68 |
Correct |
296 ms |
129672 KB |
Output is correct |
69 |
Correct |
279 ms |
129668 KB |
Output is correct |
70 |
Correct |
278 ms |
129652 KB |
Output is correct |
71 |
Correct |
277 ms |
129784 KB |
Output is correct |
72 |
Correct |
281 ms |
129672 KB |
Output is correct |
73 |
Correct |
279 ms |
129632 KB |
Output is correct |
74 |
Correct |
281 ms |
129720 KB |
Output is correct |
75 |
Correct |
278 ms |
129592 KB |
Output is correct |
76 |
Correct |
279 ms |
129776 KB |
Output is correct |
77 |
Correct |
276 ms |
129636 KB |
Output is correct |
78 |
Correct |
284 ms |
129768 KB |
Output is correct |
79 |
Correct |
276 ms |
129612 KB |
Output is correct |
80 |
Correct |
280 ms |
129768 KB |
Output is correct |
81 |
Correct |
276 ms |
129640 KB |
Output is correct |
82 |
Correct |
279 ms |
129716 KB |
Output is correct |
83 |
Correct |
283 ms |
129628 KB |
Output is correct |
84 |
Correct |
282 ms |
129820 KB |
Output is correct |
85 |
Correct |
318 ms |
129636 KB |
Output is correct |
86 |
Correct |
280 ms |
129712 KB |
Output is correct |
87 |
Correct |
286 ms |
129640 KB |
Output is correct |
88 |
Correct |
291 ms |
129700 KB |
Output is correct |
89 |
Correct |
282 ms |
129636 KB |
Output is correct |
90 |
Correct |
321 ms |
129660 KB |
Output is correct |
91 |
Correct |
285 ms |
129636 KB |
Output is correct |
92 |
Correct |
295 ms |
129640 KB |
Output is correct |
93 |
Correct |
291 ms |
129636 KB |
Output is correct |
94 |
Correct |
293 ms |
129876 KB |
Output is correct |
95 |
Correct |
289 ms |
129612 KB |
Output is correct |
96 |
Correct |
287 ms |
129640 KB |
Output is correct |
97 |
Correct |
290 ms |
129644 KB |
Output is correct |
98 |
Correct |
289 ms |
129636 KB |
Output is correct |
99 |
Correct |
311 ms |
129600 KB |
Output is correct |
100 |
Correct |
290 ms |
129636 KB |
Output is correct |
101 |
Correct |
289 ms |
129652 KB |
Output is correct |
102 |
Correct |
288 ms |
129672 KB |
Output is correct |