#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int dp[1000009][2][5];
int dis[5][5] = {
{0, 1, 1, 2, 2},
{0, 0, 1, 1, 2},
{0, 1, 0, 2, 1},
{0, 0, 0, 0, 1},
{0, 0, 0, 1, 0}
};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for(int i=0;i<=n;i++) {
for(int j=0;j<5;j++) {
dp[i][0][j] = dp[i][1][j] = 1e9;
}
}
dp[0][0][0] = 0;
string A, B;
cin >> A >> B;
for(int i=1;i<=n;i++) {
for(int j1=0;j1<2;j1++) {
for(int j2=0;j2<5;j2++) {
for(int k1=0;k1<2;k1++) {
for(int k2=0;k2<5;k2++) {
int New = A[i-1]-'0';
if(k2==2||k2==3) New = 1;
if(k2==1||k2==4) New = 0;
if(k1) New = 1-New;
if(New!=B[i-1]-'0') continue;
bool is = k1&&(!j1);
dp[i][k1][k2] = min(dp[i][k1][k2],
dp[i-1][j1][j2]+is+dis[j2][k2]);
}
}
}
}
}
int ans = 1e9;
for(int i=0;i<5;i++)
ans = min({ans, dp[n][0][i], dp[n][1][i]});
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
352 KB |
Output is correct |
27 |
Correct |
1 ms |
360 KB |
Output is correct |
28 |
Correct |
0 ms |
360 KB |
Output is correct |
29 |
Correct |
0 ms |
360 KB |
Output is correct |
30 |
Correct |
1 ms |
372 KB |
Output is correct |
31 |
Correct |
0 ms |
356 KB |
Output is correct |
32 |
Correct |
1 ms |
356 KB |
Output is correct |
33 |
Correct |
0 ms |
356 KB |
Output is correct |
34 |
Correct |
0 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
352 KB |
Output is correct |
27 |
Correct |
1 ms |
360 KB |
Output is correct |
28 |
Correct |
0 ms |
360 KB |
Output is correct |
29 |
Correct |
0 ms |
360 KB |
Output is correct |
30 |
Correct |
1 ms |
372 KB |
Output is correct |
31 |
Correct |
0 ms |
356 KB |
Output is correct |
32 |
Correct |
1 ms |
356 KB |
Output is correct |
33 |
Correct |
0 ms |
356 KB |
Output is correct |
34 |
Correct |
0 ms |
356 KB |
Output is correct |
35 |
Correct |
1 ms |
612 KB |
Output is correct |
36 |
Correct |
1 ms |
612 KB |
Output is correct |
37 |
Correct |
1 ms |
612 KB |
Output is correct |
38 |
Correct |
1 ms |
612 KB |
Output is correct |
39 |
Correct |
1 ms |
612 KB |
Output is correct |
40 |
Correct |
1 ms |
476 KB |
Output is correct |
41 |
Correct |
1 ms |
612 KB |
Output is correct |
42 |
Correct |
1 ms |
612 KB |
Output is correct |
43 |
Correct |
1 ms |
612 KB |
Output is correct |
44 |
Correct |
1 ms |
612 KB |
Output is correct |
45 |
Correct |
1 ms |
612 KB |
Output is correct |
46 |
Correct |
1 ms |
612 KB |
Output is correct |
47 |
Correct |
1 ms |
480 KB |
Output is correct |
48 |
Correct |
1 ms |
1040 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
636 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
464 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
287 ms |
82084 KB |
Output is correct |
8 |
Correct |
299 ms |
82160 KB |
Output is correct |
9 |
Correct |
290 ms |
82088 KB |
Output is correct |
10 |
Correct |
296 ms |
82156 KB |
Output is correct |
11 |
Correct |
290 ms |
82160 KB |
Output is correct |
12 |
Correct |
292 ms |
82160 KB |
Output is correct |
13 |
Correct |
284 ms |
82340 KB |
Output is correct |
14 |
Correct |
290 ms |
82160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
352 KB |
Output is correct |
27 |
Correct |
1 ms |
360 KB |
Output is correct |
28 |
Correct |
0 ms |
360 KB |
Output is correct |
29 |
Correct |
0 ms |
360 KB |
Output is correct |
30 |
Correct |
1 ms |
372 KB |
Output is correct |
31 |
Correct |
0 ms |
356 KB |
Output is correct |
32 |
Correct |
1 ms |
356 KB |
Output is correct |
33 |
Correct |
0 ms |
356 KB |
Output is correct |
34 |
Correct |
0 ms |
356 KB |
Output is correct |
35 |
Correct |
1 ms |
612 KB |
Output is correct |
36 |
Correct |
1 ms |
612 KB |
Output is correct |
37 |
Correct |
1 ms |
612 KB |
Output is correct |
38 |
Correct |
1 ms |
612 KB |
Output is correct |
39 |
Correct |
1 ms |
612 KB |
Output is correct |
40 |
Correct |
1 ms |
476 KB |
Output is correct |
41 |
Correct |
1 ms |
612 KB |
Output is correct |
42 |
Correct |
1 ms |
612 KB |
Output is correct |
43 |
Correct |
1 ms |
612 KB |
Output is correct |
44 |
Correct |
1 ms |
612 KB |
Output is correct |
45 |
Correct |
1 ms |
612 KB |
Output is correct |
46 |
Correct |
1 ms |
612 KB |
Output is correct |
47 |
Correct |
1 ms |
480 KB |
Output is correct |
48 |
Correct |
1 ms |
1040 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
636 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
464 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
344 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
287 ms |
82084 KB |
Output is correct |
66 |
Correct |
299 ms |
82160 KB |
Output is correct |
67 |
Correct |
290 ms |
82088 KB |
Output is correct |
68 |
Correct |
296 ms |
82156 KB |
Output is correct |
69 |
Correct |
290 ms |
82160 KB |
Output is correct |
70 |
Correct |
292 ms |
82160 KB |
Output is correct |
71 |
Correct |
284 ms |
82340 KB |
Output is correct |
72 |
Correct |
290 ms |
82160 KB |
Output is correct |
73 |
Correct |
289 ms |
82680 KB |
Output is correct |
74 |
Correct |
299 ms |
82680 KB |
Output is correct |
75 |
Correct |
281 ms |
82680 KB |
Output is correct |
76 |
Correct |
295 ms |
82784 KB |
Output is correct |
77 |
Correct |
280 ms |
82668 KB |
Output is correct |
78 |
Correct |
289 ms |
82844 KB |
Output is correct |
79 |
Correct |
289 ms |
82836 KB |
Output is correct |
80 |
Correct |
280 ms |
82832 KB |
Output is correct |
81 |
Correct |
284 ms |
82788 KB |
Output is correct |
82 |
Correct |
283 ms |
82796 KB |
Output is correct |
83 |
Correct |
314 ms |
82956 KB |
Output is correct |
84 |
Correct |
295 ms |
82668 KB |
Output is correct |
85 |
Correct |
297 ms |
82776 KB |
Output is correct |
86 |
Correct |
290 ms |
82668 KB |
Output is correct |
87 |
Correct |
334 ms |
82780 KB |
Output is correct |
88 |
Correct |
297 ms |
82672 KB |
Output is correct |
89 |
Correct |
318 ms |
82816 KB |
Output is correct |
90 |
Correct |
296 ms |
82780 KB |
Output is correct |
91 |
Correct |
298 ms |
82780 KB |
Output is correct |
92 |
Correct |
308 ms |
82924 KB |
Output is correct |
93 |
Correct |
307 ms |
82768 KB |
Output is correct |
94 |
Correct |
306 ms |
82832 KB |
Output is correct |
95 |
Correct |
299 ms |
82776 KB |
Output is correct |
96 |
Correct |
300 ms |
82784 KB |
Output is correct |
97 |
Correct |
298 ms |
82780 KB |
Output is correct |
98 |
Correct |
313 ms |
82780 KB |
Output is correct |
99 |
Correct |
301 ms |
82712 KB |
Output is correct |
100 |
Correct |
304 ms |
83012 KB |
Output is correct |
101 |
Correct |
301 ms |
82732 KB |
Output is correct |
102 |
Correct |
309 ms |
82680 KB |
Output is correct |