#include <iostream>
#include <algorithm>
using namespace std;
const int NMAX = 1e6;
const int inf = 1e9;
int n;
string s;
string t;
int dp[NMAX + 5][3][2];
void trans(int i,int j,int k,int ii,int jj,int kk){
if(i != ii - 1){
return ;
}
if(jj == 0){
if(s[ii] - '0' != ((t[ii] - '0') ^ kk)){
return ;
}
// if(ii == 1 && jj == 0 && kk == 1)printf("1 %d %d %d val %d actual %d\n",i,j,k,dp[i][j][k],dp[i][j][k] + (k == 0 && kk == 1));
dp[ii][jj][kk] = min(dp[ii][jj][kk],dp[i][j][k] + (k == 0 && kk == 1));
return ;
}
if(t[ii] - '0' != ((jj - 1) ^ kk)){
return ;
}
// if(ii == 1 && jj == 0 && kk == 1)printf("2 %d %d %d val %d actual %d\n",i,j,k,dp[i][j][k],dp[i][j][k] + (k == 0 && kk == 1) + (j != jj));
dp[ii][jj][kk] = min(dp[ii][jj][kk],dp[i][j][k] + (k == 0 && kk == 1) + (j != jj));
}
int main(){
cin >> n;
cin >> s;
cin >> t;
s = " " + s;
t = " " + t;
dp[0][0][1] = inf;
dp[0][1][0] = inf;
dp[0][1][1] = inf;
dp[0][2][0] = inf;
dp[0][2][1] = inf;
for(int i = 1;i <= n;i++){
for(int j = 0;j < 3;j++){
for(int k = 0;k < 2;k++){
dp[i][j][k] = inf;
for(int jj = 0;jj < 3;jj++){
for(int kk = 0;kk < 2;kk++){
trans(i - 1,jj,kk,i,j,k);
}
}
}
}
}
int ans = inf;
for(int i = 0;i < 3;i++){
for(int j = 0;j < 2;j++){
ans = min(ans,dp[n][i][j]);
}
}
printf("%d\n",ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
276 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
360 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
360 KB |
Output is correct |
34 |
Correct |
2 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
276 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
360 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
360 KB |
Output is correct |
34 |
Correct |
2 ms |
292 KB |
Output is correct |
35 |
Correct |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
376 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
380 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
376 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
372 KB |
Output is correct |
46 |
Correct |
3 ms |
376 KB |
Output is correct |
47 |
Correct |
3 ms |
380 KB |
Output is correct |
48 |
Correct |
3 ms |
376 KB |
Output is correct |
49 |
Correct |
3 ms |
376 KB |
Output is correct |
50 |
Correct |
3 ms |
376 KB |
Output is correct |
51 |
Correct |
3 ms |
376 KB |
Output is correct |
52 |
Correct |
3 ms |
376 KB |
Output is correct |
53 |
Correct |
3 ms |
376 KB |
Output is correct |
54 |
Correct |
3 ms |
376 KB |
Output is correct |
55 |
Correct |
3 ms |
376 KB |
Output is correct |
56 |
Correct |
3 ms |
376 KB |
Output is correct |
57 |
Correct |
3 ms |
376 KB |
Output is correct |
58 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
309 ms |
27832 KB |
Output is correct |
8 |
Correct |
309 ms |
27844 KB |
Output is correct |
9 |
Correct |
322 ms |
27840 KB |
Output is correct |
10 |
Correct |
307 ms |
27828 KB |
Output is correct |
11 |
Correct |
313 ms |
27744 KB |
Output is correct |
12 |
Correct |
310 ms |
27732 KB |
Output is correct |
13 |
Correct |
309 ms |
27688 KB |
Output is correct |
14 |
Correct |
309 ms |
27832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
276 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
360 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
360 KB |
Output is correct |
34 |
Correct |
2 ms |
292 KB |
Output is correct |
35 |
Correct |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
376 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
380 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
376 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
372 KB |
Output is correct |
46 |
Correct |
3 ms |
376 KB |
Output is correct |
47 |
Correct |
3 ms |
380 KB |
Output is correct |
48 |
Correct |
3 ms |
376 KB |
Output is correct |
49 |
Correct |
3 ms |
376 KB |
Output is correct |
50 |
Correct |
3 ms |
376 KB |
Output is correct |
51 |
Correct |
3 ms |
376 KB |
Output is correct |
52 |
Correct |
3 ms |
376 KB |
Output is correct |
53 |
Correct |
3 ms |
376 KB |
Output is correct |
54 |
Correct |
3 ms |
376 KB |
Output is correct |
55 |
Correct |
3 ms |
376 KB |
Output is correct |
56 |
Correct |
3 ms |
376 KB |
Output is correct |
57 |
Correct |
3 ms |
376 KB |
Output is correct |
58 |
Correct |
3 ms |
376 KB |
Output is correct |
59 |
Correct |
2 ms |
256 KB |
Output is correct |
60 |
Correct |
2 ms |
256 KB |
Output is correct |
61 |
Correct |
2 ms |
256 KB |
Output is correct |
62 |
Correct |
2 ms |
256 KB |
Output is correct |
63 |
Correct |
2 ms |
376 KB |
Output is correct |
64 |
Correct |
2 ms |
376 KB |
Output is correct |
65 |
Correct |
309 ms |
27832 KB |
Output is correct |
66 |
Correct |
309 ms |
27844 KB |
Output is correct |
67 |
Correct |
322 ms |
27840 KB |
Output is correct |
68 |
Correct |
307 ms |
27828 KB |
Output is correct |
69 |
Correct |
313 ms |
27744 KB |
Output is correct |
70 |
Correct |
310 ms |
27732 KB |
Output is correct |
71 |
Correct |
309 ms |
27688 KB |
Output is correct |
72 |
Correct |
309 ms |
27832 KB |
Output is correct |
73 |
Correct |
319 ms |
27804 KB |
Output is correct |
74 |
Correct |
330 ms |
27700 KB |
Output is correct |
75 |
Correct |
311 ms |
27856 KB |
Output is correct |
76 |
Correct |
316 ms |
27780 KB |
Output is correct |
77 |
Correct |
325 ms |
27828 KB |
Output is correct |
78 |
Correct |
311 ms |
27800 KB |
Output is correct |
79 |
Correct |
307 ms |
27740 KB |
Output is correct |
80 |
Correct |
311 ms |
27836 KB |
Output is correct |
81 |
Correct |
395 ms |
27976 KB |
Output is correct |
82 |
Correct |
316 ms |
27836 KB |
Output is correct |
83 |
Correct |
318 ms |
27800 KB |
Output is correct |
84 |
Correct |
483 ms |
27956 KB |
Output is correct |
85 |
Correct |
320 ms |
27700 KB |
Output is correct |
86 |
Correct |
321 ms |
27860 KB |
Output is correct |
87 |
Correct |
491 ms |
27820 KB |
Output is correct |
88 |
Correct |
320 ms |
27828 KB |
Output is correct |
89 |
Correct |
325 ms |
27876 KB |
Output is correct |
90 |
Correct |
320 ms |
27828 KB |
Output is correct |
91 |
Correct |
333 ms |
27736 KB |
Output is correct |
92 |
Correct |
332 ms |
27700 KB |
Output is correct |
93 |
Correct |
329 ms |
27700 KB |
Output is correct |
94 |
Correct |
339 ms |
27708 KB |
Output is correct |
95 |
Correct |
330 ms |
27704 KB |
Output is correct |
96 |
Correct |
328 ms |
27780 KB |
Output is correct |
97 |
Correct |
329 ms |
27836 KB |
Output is correct |
98 |
Correct |
327 ms |
27704 KB |
Output is correct |
99 |
Correct |
328 ms |
27704 KB |
Output is correct |
100 |
Correct |
510 ms |
27848 KB |
Output is correct |
101 |
Correct |
327 ms |
27908 KB |
Output is correct |
102 |
Correct |
328 ms |
27760 KB |
Output is correct |