#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<unordered_map>
#include<set>
#include<algorithm>
#define ll int
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 1000004
#define INF 1000004
using namespace std;
ll n;
string s,t;
int dp[N][6];
/* 0: den ekana operation sto i, 1: kame to i set se 1, 2: kame to i set se 0,
3:kame to i toggle, 4: kame to i 1 kai meta toggle, 5: kame to i 0 kai meta toggle
*/
void solve()
{
if(s[0]==t[0])
{
dp[0][0] = 0;
dp[0][3] = INF;
}
else
{
dp[0][0] = INF;
dp[0][3] = 1;
}
if(t[0] == '0')
{
dp[0][2] = 1;
dp[0][1] = INF;
dp[0][4] = 2;
dp[0][5] = INF;
}
else
{
dp[0][1] = 1;
dp[0][2] = INF;
dp[0][4] = INF;
dp[0][5] = 2;
}
rep(i,1,n)
{
if(s[i] == t[i])
{
dp[i][0] = min(dp[i-1][0],dp[i-1][1]);
dp[i][0] = min(dp[i][0],dp[i-1][2]);
dp[i][0] = min(dp[i][0],dp[i-1][3]);
dp[i][0] = min(dp[i][0],dp[i-1][4]);
dp[i][0] = min(dp[i][0],dp[i-1][5]);
dp[i][3] = INF;
}
else
{
dp[i][0] = INF;
dp[i][3] = min(dp[i-1][0]+1,dp[i-1][1]+1);
dp[i][3] = min(dp[i][3],dp[i-1][2]+1);
dp[i][3] = min(dp[i][3],dp[i-1][3]);
dp[i][3] = min(dp[i][3],dp[i-1][4]);
dp[i][3] = min(dp[i][3],dp[i-1][5]);
}
if(t[i] == '1')
{
dp[i][2] = INF;
dp[i][1] = min(dp[i-1][0]+1,dp[i-1][1]);
dp[i][1] = min(dp[i][1],dp[i-1][2]+1);
dp[i][1] = min(dp[i][1],dp[i-1][3]+1);
dp[i][1] = min(dp[i][1],dp[i-1][4]);
dp[i][1] = min(dp[i][1],dp[i-1][5]+1);
dp[i][4] = INF;
dp[i][5] = min(dp[i-1][0]+2,dp[i-1][1]+2);
dp[i][5] = min(dp[i][5],dp[i-1][2]+1);
dp[i][5] = min(dp[i][5],dp[i-1][3]+1);
dp[i][5] = min(dp[i][5],dp[i-1][4]+1);
dp[i][5] = min(dp[i][5],dp[i-1][5]);
}
else
{
dp[i][1] = INF;
dp[i][2] = min(dp[i-1][0]+1,dp[i-1][2]);
dp[i][2] = min(dp[i][2],dp[i-1][1]+1);
dp[i][2] = min(dp[i][2],dp[i-1][3]+1);
dp[i][2] = min(dp[i][2],dp[i-1][4]+1);
dp[i][2] = min(dp[i][2],dp[i-1][5]);
dp[i][5] = INF;
dp[i][4] = min(dp[i-1][0]+2,dp[i-1][2]+2);
dp[i][4] = min(dp[i][4],dp[i-1][1]+1);
dp[i][4] = min(dp[i][4],dp[i-1][3]+1);
dp[i][4] = min(dp[i][4],dp[i-1][4]);
dp[i][4] = min(dp[i][4],dp[i-1][5]+1);
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cin >> s;
cin >> t;
solve();
cout << min({dp[n-1][0],dp[n-1][1],dp[n-1][2],dp[n-1][3],dp[n-1][4],dp[n-1][5]});
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
432 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
432 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
384 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
5 ms |
384 KB |
Output is correct |
54 |
Correct |
5 ms |
384 KB |
Output is correct |
55 |
Correct |
5 ms |
384 KB |
Output is correct |
56 |
Correct |
5 ms |
384 KB |
Output is correct |
57 |
Correct |
5 ms |
384 KB |
Output is correct |
58 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
29 ms |
25932 KB |
Output is correct |
8 |
Correct |
29 ms |
27984 KB |
Output is correct |
9 |
Correct |
30 ms |
27852 KB |
Output is correct |
10 |
Correct |
31 ms |
27860 KB |
Output is correct |
11 |
Correct |
30 ms |
27860 KB |
Output is correct |
12 |
Correct |
31 ms |
27988 KB |
Output is correct |
13 |
Correct |
30 ms |
27852 KB |
Output is correct |
14 |
Correct |
31 ms |
27852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
432 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
5 ms |
384 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
5 ms |
384 KB |
Output is correct |
54 |
Correct |
5 ms |
384 KB |
Output is correct |
55 |
Correct |
5 ms |
384 KB |
Output is correct |
56 |
Correct |
5 ms |
384 KB |
Output is correct |
57 |
Correct |
5 ms |
384 KB |
Output is correct |
58 |
Correct |
5 ms |
384 KB |
Output is correct |
59 |
Correct |
5 ms |
384 KB |
Output is correct |
60 |
Correct |
5 ms |
384 KB |
Output is correct |
61 |
Correct |
5 ms |
384 KB |
Output is correct |
62 |
Correct |
5 ms |
384 KB |
Output is correct |
63 |
Correct |
4 ms |
384 KB |
Output is correct |
64 |
Correct |
5 ms |
384 KB |
Output is correct |
65 |
Correct |
29 ms |
25932 KB |
Output is correct |
66 |
Correct |
29 ms |
27984 KB |
Output is correct |
67 |
Correct |
30 ms |
27852 KB |
Output is correct |
68 |
Correct |
31 ms |
27860 KB |
Output is correct |
69 |
Correct |
30 ms |
27860 KB |
Output is correct |
70 |
Correct |
31 ms |
27988 KB |
Output is correct |
71 |
Correct |
30 ms |
27852 KB |
Output is correct |
72 |
Correct |
31 ms |
27852 KB |
Output is correct |
73 |
Correct |
33 ms |
27852 KB |
Output is correct |
74 |
Correct |
30 ms |
27848 KB |
Output is correct |
75 |
Correct |
32 ms |
27860 KB |
Output is correct |
76 |
Correct |
30 ms |
27852 KB |
Output is correct |
77 |
Correct |
30 ms |
27852 KB |
Output is correct |
78 |
Correct |
31 ms |
27820 KB |
Output is correct |
79 |
Correct |
30 ms |
27852 KB |
Output is correct |
80 |
Correct |
30 ms |
27852 KB |
Output is correct |
81 |
Correct |
30 ms |
27860 KB |
Output is correct |
82 |
Correct |
30 ms |
27852 KB |
Output is correct |
83 |
Correct |
33 ms |
27972 KB |
Output is correct |
84 |
Correct |
35 ms |
27844 KB |
Output is correct |
85 |
Correct |
34 ms |
27860 KB |
Output is correct |
86 |
Correct |
33 ms |
27852 KB |
Output is correct |
87 |
Correct |
36 ms |
27852 KB |
Output is correct |
88 |
Correct |
34 ms |
27860 KB |
Output is correct |
89 |
Correct |
35 ms |
27852 KB |
Output is correct |
90 |
Correct |
34 ms |
27844 KB |
Output is correct |
91 |
Correct |
35 ms |
27852 KB |
Output is correct |
92 |
Correct |
36 ms |
27852 KB |
Output is correct |
93 |
Correct |
39 ms |
27852 KB |
Output is correct |
94 |
Correct |
37 ms |
27860 KB |
Output is correct |
95 |
Correct |
38 ms |
27844 KB |
Output is correct |
96 |
Correct |
39 ms |
27980 KB |
Output is correct |
97 |
Correct |
36 ms |
27852 KB |
Output is correct |
98 |
Correct |
47 ms |
27836 KB |
Output is correct |
99 |
Correct |
38 ms |
27848 KB |
Output is correct |
100 |
Correct |
37 ms |
27852 KB |
Output is correct |
101 |
Correct |
36 ms |
27848 KB |
Output is correct |
102 |
Correct |
36 ms |
27852 KB |
Output is correct |