#include<iostream>
using namespace std;
const int N=1e6+2;
const int inf=1e9+7;
int dp[N][5][3];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,i,j,k,l,m,z;
string a,b;
cin>>n>>a>>b;
a=" "+a;
b=" "+b;
for(j=0;j<3;j++){
for(k=0;k<2;k++){
dp[0][j][k]=inf;
}
}
dp[0][0][0]=0;
for(i=1;i<=n;i++){
for(j=0;j<3;j++){
for(k=0;k<2;k++){
dp[i][j][k]=inf;
if(j>0){
z=j-1;
}
else{
z=(int)(a[i]-'0');
}
if(k){
z=1-z;
}
if(z!=(int)(b[i]-'0')){
continue;
}
for(l=0;l<3;l++){
for(m=0;m<2;m++){
z=0;
if(j>0&&j!=l){
z++;
}
if(k==1&&m==0){
z++;
}
dp[i][j][k]=min(dp[i][j][k],dp[i-1][l][m]+z);
}
}
// cout<<dp[i][j][k]<<' '<<i<<' '<<j<<' '<<k<<endl;
}
}
}
for(j=0;j<3;j++){
for(k=0;k<2;k++){
dp[n][0][0]=min(dp[n][0][0],dp[n][j][k]);
}
}
cout<<dp[n][0][0];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
376 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 |
376 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 |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
380 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 |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
376 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 |
376 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 |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
380 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 |
420 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
3 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
504 KB |
Output is correct |
42 |
Correct |
3 ms |
504 KB |
Output is correct |
43 |
Correct |
2 ms |
504 KB |
Output is correct |
44 |
Correct |
3 ms |
504 KB |
Output is correct |
45 |
Correct |
2 ms |
504 KB |
Output is correct |
46 |
Correct |
2 ms |
504 KB |
Output is correct |
47 |
Correct |
3 ms |
504 KB |
Output is correct |
48 |
Correct |
3 ms |
504 KB |
Output is correct |
49 |
Correct |
3 ms |
504 KB |
Output is correct |
50 |
Correct |
3 ms |
504 KB |
Output is correct |
51 |
Correct |
3 ms |
504 KB |
Output is correct |
52 |
Correct |
2 ms |
504 KB |
Output is correct |
53 |
Correct |
3 ms |
504 KB |
Output is correct |
54 |
Correct |
3 ms |
504 KB |
Output is correct |
55 |
Correct |
3 ms |
504 KB |
Output is correct |
56 |
Correct |
2 ms |
504 KB |
Output is correct |
57 |
Correct |
2 ms |
504 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 |
372 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 |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
97 ms |
63008 KB |
Output is correct |
8 |
Correct |
96 ms |
62936 KB |
Output is correct |
9 |
Correct |
95 ms |
63008 KB |
Output is correct |
10 |
Correct |
95 ms |
63000 KB |
Output is correct |
11 |
Correct |
96 ms |
63008 KB |
Output is correct |
12 |
Correct |
95 ms |
63008 KB |
Output is correct |
13 |
Correct |
95 ms |
62996 KB |
Output is correct |
14 |
Correct |
95 ms |
63000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
376 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 |
376 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 |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
380 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 |
420 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
3 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
504 KB |
Output is correct |
42 |
Correct |
3 ms |
504 KB |
Output is correct |
43 |
Correct |
2 ms |
504 KB |
Output is correct |
44 |
Correct |
3 ms |
504 KB |
Output is correct |
45 |
Correct |
2 ms |
504 KB |
Output is correct |
46 |
Correct |
2 ms |
504 KB |
Output is correct |
47 |
Correct |
3 ms |
504 KB |
Output is correct |
48 |
Correct |
3 ms |
504 KB |
Output is correct |
49 |
Correct |
3 ms |
504 KB |
Output is correct |
50 |
Correct |
3 ms |
504 KB |
Output is correct |
51 |
Correct |
3 ms |
504 KB |
Output is correct |
52 |
Correct |
2 ms |
504 KB |
Output is correct |
53 |
Correct |
3 ms |
504 KB |
Output is correct |
54 |
Correct |
3 ms |
504 KB |
Output is correct |
55 |
Correct |
3 ms |
504 KB |
Output is correct |
56 |
Correct |
2 ms |
504 KB |
Output is correct |
57 |
Correct |
2 ms |
504 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 |
372 KB |
Output is correct |
61 |
Correct |
2 ms |
376 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
63 |
Correct |
2 ms |
380 KB |
Output is correct |
64 |
Correct |
2 ms |
376 KB |
Output is correct |
65 |
Correct |
97 ms |
63008 KB |
Output is correct |
66 |
Correct |
96 ms |
62936 KB |
Output is correct |
67 |
Correct |
95 ms |
63008 KB |
Output is correct |
68 |
Correct |
95 ms |
63000 KB |
Output is correct |
69 |
Correct |
96 ms |
63008 KB |
Output is correct |
70 |
Correct |
95 ms |
63008 KB |
Output is correct |
71 |
Correct |
95 ms |
62996 KB |
Output is correct |
72 |
Correct |
95 ms |
63000 KB |
Output is correct |
73 |
Correct |
95 ms |
63092 KB |
Output is correct |
74 |
Correct |
96 ms |
63060 KB |
Output is correct |
75 |
Correct |
103 ms |
63132 KB |
Output is correct |
76 |
Correct |
106 ms |
63036 KB |
Output is correct |
77 |
Correct |
106 ms |
62932 KB |
Output is correct |
78 |
Correct |
105 ms |
62884 KB |
Output is correct |
79 |
Correct |
101 ms |
62956 KB |
Output is correct |
80 |
Correct |
95 ms |
63008 KB |
Output is correct |
81 |
Correct |
96 ms |
63000 KB |
Output is correct |
82 |
Correct |
96 ms |
63004 KB |
Output is correct |
83 |
Correct |
101 ms |
63008 KB |
Output is correct |
84 |
Correct |
104 ms |
63048 KB |
Output is correct |
85 |
Correct |
103 ms |
63008 KB |
Output is correct |
86 |
Correct |
102 ms |
63008 KB |
Output is correct |
87 |
Correct |
102 ms |
63020 KB |
Output is correct |
88 |
Correct |
102 ms |
62920 KB |
Output is correct |
89 |
Correct |
102 ms |
63008 KB |
Output is correct |
90 |
Correct |
103 ms |
63004 KB |
Output is correct |
91 |
Correct |
105 ms |
62988 KB |
Output is correct |
92 |
Correct |
105 ms |
62964 KB |
Output is correct |
93 |
Correct |
108 ms |
63004 KB |
Output is correct |
94 |
Correct |
106 ms |
62908 KB |
Output is correct |
95 |
Correct |
106 ms |
63004 KB |
Output is correct |
96 |
Correct |
106 ms |
63000 KB |
Output is correct |
97 |
Correct |
106 ms |
63004 KB |
Output is correct |
98 |
Correct |
106 ms |
63000 KB |
Output is correct |
99 |
Correct |
107 ms |
63004 KB |
Output is correct |
100 |
Correct |
107 ms |
62972 KB |
Output is correct |
101 |
Correct |
107 ms |
63060 KB |
Output is correct |
102 |
Correct |
108 ms |
62924 KB |
Output is correct |