//#include"holiday.h"
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 1e6 + 7;
int Mod = 1e9 + 7;///lon
const int INF = 1e9;
const ll BASE = 137;
const int szBL = 450;
int n;
int a[N], b[N];
int dp[N][3][2];
void solution () {
cin >> n;
{
string s;
cin >> s;
rep (i, 1, n) a[i] = s[i - 1] - '0';
}
{
string s;
cin >> s;
rep (i, 1, n) b[i] = s[i - 1] - '0';
}
memset(dp, 0x3f, sizeof dp);
dp[0][2][0] = 0;
rep (i, 1, n) {
rep (j, 0, 2)
rep (k, 0, 1) {
int bt = j == 2 ? a[i] ^ k : j ^ k;
if (bt != b[i]) continue;
rep (j2, 0, 2)
rep (k2, 0, 1) {
dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j2][k2] + (j2 != j && j != 2) + (k2 != k && k != 0));
}
}
}
int res = INF;
rep (j, 0, 2)
rep (k, 0, 1) res = min(res, dp[n][j][k]);
cout << res <<"\n";
}
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
// file("c");
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
no bug challenge +10
5 5
01101
10001
00110
10101
00100
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
27220 KB |
Output is correct |
2 |
Correct |
4 ms |
27384 KB |
Output is correct |
3 |
Correct |
3 ms |
27272 KB |
Output is correct |
4 |
Correct |
3 ms |
27304 KB |
Output is correct |
5 |
Correct |
4 ms |
27220 KB |
Output is correct |
6 |
Correct |
3 ms |
27220 KB |
Output is correct |
7 |
Correct |
4 ms |
27220 KB |
Output is correct |
8 |
Correct |
3 ms |
27220 KB |
Output is correct |
9 |
Correct |
4 ms |
27232 KB |
Output is correct |
10 |
Correct |
3 ms |
27220 KB |
Output is correct |
11 |
Correct |
4 ms |
27220 KB |
Output is correct |
12 |
Correct |
4 ms |
27220 KB |
Output is correct |
13 |
Correct |
3 ms |
27220 KB |
Output is correct |
14 |
Correct |
4 ms |
27220 KB |
Output is correct |
15 |
Correct |
4 ms |
27220 KB |
Output is correct |
16 |
Correct |
4 ms |
27220 KB |
Output is correct |
17 |
Correct |
4 ms |
27316 KB |
Output is correct |
18 |
Correct |
5 ms |
27236 KB |
Output is correct |
19 |
Correct |
4 ms |
27220 KB |
Output is correct |
20 |
Correct |
4 ms |
27384 KB |
Output is correct |
21 |
Correct |
4 ms |
27324 KB |
Output is correct |
22 |
Correct |
4 ms |
27220 KB |
Output is correct |
23 |
Correct |
4 ms |
27384 KB |
Output is correct |
24 |
Correct |
4 ms |
27220 KB |
Output is correct |
25 |
Correct |
5 ms |
27220 KB |
Output is correct |
26 |
Correct |
4 ms |
27220 KB |
Output is correct |
27 |
Correct |
3 ms |
27220 KB |
Output is correct |
28 |
Correct |
4 ms |
27220 KB |
Output is correct |
29 |
Correct |
4 ms |
27220 KB |
Output is correct |
30 |
Correct |
4 ms |
27220 KB |
Output is correct |
31 |
Correct |
4 ms |
27220 KB |
Output is correct |
32 |
Correct |
4 ms |
27220 KB |
Output is correct |
33 |
Correct |
4 ms |
27220 KB |
Output is correct |
34 |
Correct |
4 ms |
27220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
27220 KB |
Output is correct |
2 |
Correct |
4 ms |
27384 KB |
Output is correct |
3 |
Correct |
3 ms |
27272 KB |
Output is correct |
4 |
Correct |
3 ms |
27304 KB |
Output is correct |
5 |
Correct |
4 ms |
27220 KB |
Output is correct |
6 |
Correct |
3 ms |
27220 KB |
Output is correct |
7 |
Correct |
4 ms |
27220 KB |
Output is correct |
8 |
Correct |
3 ms |
27220 KB |
Output is correct |
9 |
Correct |
4 ms |
27232 KB |
Output is correct |
10 |
Correct |
3 ms |
27220 KB |
Output is correct |
11 |
Correct |
4 ms |
27220 KB |
Output is correct |
12 |
Correct |
4 ms |
27220 KB |
Output is correct |
13 |
Correct |
3 ms |
27220 KB |
Output is correct |
14 |
Correct |
4 ms |
27220 KB |
Output is correct |
15 |
Correct |
4 ms |
27220 KB |
Output is correct |
16 |
Correct |
4 ms |
27220 KB |
Output is correct |
17 |
Correct |
4 ms |
27316 KB |
Output is correct |
18 |
Correct |
5 ms |
27236 KB |
Output is correct |
19 |
Correct |
4 ms |
27220 KB |
Output is correct |
20 |
Correct |
4 ms |
27384 KB |
Output is correct |
21 |
Correct |
4 ms |
27324 KB |
Output is correct |
22 |
Correct |
4 ms |
27220 KB |
Output is correct |
23 |
Correct |
4 ms |
27384 KB |
Output is correct |
24 |
Correct |
4 ms |
27220 KB |
Output is correct |
25 |
Correct |
5 ms |
27220 KB |
Output is correct |
26 |
Correct |
4 ms |
27220 KB |
Output is correct |
27 |
Correct |
3 ms |
27220 KB |
Output is correct |
28 |
Correct |
4 ms |
27220 KB |
Output is correct |
29 |
Correct |
4 ms |
27220 KB |
Output is correct |
30 |
Correct |
4 ms |
27220 KB |
Output is correct |
31 |
Correct |
4 ms |
27220 KB |
Output is correct |
32 |
Correct |
4 ms |
27220 KB |
Output is correct |
33 |
Correct |
4 ms |
27220 KB |
Output is correct |
34 |
Correct |
4 ms |
27220 KB |
Output is correct |
35 |
Correct |
4 ms |
27220 KB |
Output is correct |
36 |
Correct |
4 ms |
27220 KB |
Output is correct |
37 |
Correct |
4 ms |
27324 KB |
Output is correct |
38 |
Correct |
4 ms |
27220 KB |
Output is correct |
39 |
Correct |
4 ms |
27092 KB |
Output is correct |
40 |
Correct |
12 ms |
27384 KB |
Output is correct |
41 |
Correct |
6 ms |
27220 KB |
Output is correct |
42 |
Correct |
4 ms |
27384 KB |
Output is correct |
43 |
Correct |
4 ms |
27220 KB |
Output is correct |
44 |
Correct |
4 ms |
27220 KB |
Output is correct |
45 |
Correct |
4 ms |
27220 KB |
Output is correct |
46 |
Correct |
4 ms |
27220 KB |
Output is correct |
47 |
Correct |
4 ms |
27220 KB |
Output is correct |
48 |
Correct |
4 ms |
27260 KB |
Output is correct |
49 |
Correct |
4 ms |
27232 KB |
Output is correct |
50 |
Correct |
4 ms |
27220 KB |
Output is correct |
51 |
Correct |
4 ms |
27232 KB |
Output is correct |
52 |
Correct |
4 ms |
27220 KB |
Output is correct |
53 |
Correct |
4 ms |
27220 KB |
Output is correct |
54 |
Correct |
4 ms |
27220 KB |
Output is correct |
55 |
Correct |
4 ms |
27468 KB |
Output is correct |
56 |
Correct |
4 ms |
27312 KB |
Output is correct |
57 |
Correct |
5 ms |
27220 KB |
Output is correct |
58 |
Correct |
4 ms |
27284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
27220 KB |
Output is correct |
2 |
Correct |
11 ms |
27220 KB |
Output is correct |
3 |
Correct |
4 ms |
27220 KB |
Output is correct |
4 |
Correct |
10 ms |
27220 KB |
Output is correct |
5 |
Correct |
6 ms |
27220 KB |
Output is correct |
6 |
Correct |
6 ms |
27220 KB |
Output is correct |
7 |
Correct |
26 ms |
33748 KB |
Output is correct |
8 |
Correct |
27 ms |
33788 KB |
Output is correct |
9 |
Correct |
27 ms |
33792 KB |
Output is correct |
10 |
Correct |
28 ms |
33788 KB |
Output is correct |
11 |
Correct |
28 ms |
33784 KB |
Output is correct |
12 |
Correct |
33 ms |
33792 KB |
Output is correct |
13 |
Correct |
31 ms |
33788 KB |
Output is correct |
14 |
Correct |
30 ms |
33808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
27220 KB |
Output is correct |
2 |
Correct |
4 ms |
27384 KB |
Output is correct |
3 |
Correct |
3 ms |
27272 KB |
Output is correct |
4 |
Correct |
3 ms |
27304 KB |
Output is correct |
5 |
Correct |
4 ms |
27220 KB |
Output is correct |
6 |
Correct |
3 ms |
27220 KB |
Output is correct |
7 |
Correct |
4 ms |
27220 KB |
Output is correct |
8 |
Correct |
3 ms |
27220 KB |
Output is correct |
9 |
Correct |
4 ms |
27232 KB |
Output is correct |
10 |
Correct |
3 ms |
27220 KB |
Output is correct |
11 |
Correct |
4 ms |
27220 KB |
Output is correct |
12 |
Correct |
4 ms |
27220 KB |
Output is correct |
13 |
Correct |
3 ms |
27220 KB |
Output is correct |
14 |
Correct |
4 ms |
27220 KB |
Output is correct |
15 |
Correct |
4 ms |
27220 KB |
Output is correct |
16 |
Correct |
4 ms |
27220 KB |
Output is correct |
17 |
Correct |
4 ms |
27316 KB |
Output is correct |
18 |
Correct |
5 ms |
27236 KB |
Output is correct |
19 |
Correct |
4 ms |
27220 KB |
Output is correct |
20 |
Correct |
4 ms |
27384 KB |
Output is correct |
21 |
Correct |
4 ms |
27324 KB |
Output is correct |
22 |
Correct |
4 ms |
27220 KB |
Output is correct |
23 |
Correct |
4 ms |
27384 KB |
Output is correct |
24 |
Correct |
4 ms |
27220 KB |
Output is correct |
25 |
Correct |
5 ms |
27220 KB |
Output is correct |
26 |
Correct |
4 ms |
27220 KB |
Output is correct |
27 |
Correct |
3 ms |
27220 KB |
Output is correct |
28 |
Correct |
4 ms |
27220 KB |
Output is correct |
29 |
Correct |
4 ms |
27220 KB |
Output is correct |
30 |
Correct |
4 ms |
27220 KB |
Output is correct |
31 |
Correct |
4 ms |
27220 KB |
Output is correct |
32 |
Correct |
4 ms |
27220 KB |
Output is correct |
33 |
Correct |
4 ms |
27220 KB |
Output is correct |
34 |
Correct |
4 ms |
27220 KB |
Output is correct |
35 |
Correct |
4 ms |
27220 KB |
Output is correct |
36 |
Correct |
4 ms |
27220 KB |
Output is correct |
37 |
Correct |
4 ms |
27324 KB |
Output is correct |
38 |
Correct |
4 ms |
27220 KB |
Output is correct |
39 |
Correct |
4 ms |
27092 KB |
Output is correct |
40 |
Correct |
12 ms |
27384 KB |
Output is correct |
41 |
Correct |
6 ms |
27220 KB |
Output is correct |
42 |
Correct |
4 ms |
27384 KB |
Output is correct |
43 |
Correct |
4 ms |
27220 KB |
Output is correct |
44 |
Correct |
4 ms |
27220 KB |
Output is correct |
45 |
Correct |
4 ms |
27220 KB |
Output is correct |
46 |
Correct |
4 ms |
27220 KB |
Output is correct |
47 |
Correct |
4 ms |
27220 KB |
Output is correct |
48 |
Correct |
4 ms |
27260 KB |
Output is correct |
49 |
Correct |
4 ms |
27232 KB |
Output is correct |
50 |
Correct |
4 ms |
27220 KB |
Output is correct |
51 |
Correct |
4 ms |
27232 KB |
Output is correct |
52 |
Correct |
4 ms |
27220 KB |
Output is correct |
53 |
Correct |
4 ms |
27220 KB |
Output is correct |
54 |
Correct |
4 ms |
27220 KB |
Output is correct |
55 |
Correct |
4 ms |
27468 KB |
Output is correct |
56 |
Correct |
4 ms |
27312 KB |
Output is correct |
57 |
Correct |
5 ms |
27220 KB |
Output is correct |
58 |
Correct |
4 ms |
27284 KB |
Output is correct |
59 |
Correct |
4 ms |
27220 KB |
Output is correct |
60 |
Correct |
11 ms |
27220 KB |
Output is correct |
61 |
Correct |
4 ms |
27220 KB |
Output is correct |
62 |
Correct |
10 ms |
27220 KB |
Output is correct |
63 |
Correct |
6 ms |
27220 KB |
Output is correct |
64 |
Correct |
6 ms |
27220 KB |
Output is correct |
65 |
Correct |
26 ms |
33748 KB |
Output is correct |
66 |
Correct |
27 ms |
33788 KB |
Output is correct |
67 |
Correct |
27 ms |
33792 KB |
Output is correct |
68 |
Correct |
28 ms |
33788 KB |
Output is correct |
69 |
Correct |
28 ms |
33784 KB |
Output is correct |
70 |
Correct |
33 ms |
33792 KB |
Output is correct |
71 |
Correct |
31 ms |
33788 KB |
Output is correct |
72 |
Correct |
30 ms |
33808 KB |
Output is correct |
73 |
Correct |
28 ms |
33788 KB |
Output is correct |
74 |
Correct |
28 ms |
33648 KB |
Output is correct |
75 |
Correct |
32 ms |
33788 KB |
Output is correct |
76 |
Correct |
34 ms |
33788 KB |
Output is correct |
77 |
Correct |
25 ms |
33788 KB |
Output is correct |
78 |
Correct |
26 ms |
33788 KB |
Output is correct |
79 |
Correct |
29 ms |
33792 KB |
Output is correct |
80 |
Correct |
41 ms |
33804 KB |
Output is correct |
81 |
Correct |
26 ms |
33792 KB |
Output is correct |
82 |
Correct |
26 ms |
33724 KB |
Output is correct |
83 |
Correct |
30 ms |
33788 KB |
Output is correct |
84 |
Correct |
30 ms |
33788 KB |
Output is correct |
85 |
Correct |
31 ms |
33620 KB |
Output is correct |
86 |
Correct |
34 ms |
33788 KB |
Output is correct |
87 |
Correct |
34 ms |
33836 KB |
Output is correct |
88 |
Correct |
30 ms |
33788 KB |
Output is correct |
89 |
Correct |
30 ms |
33788 KB |
Output is correct |
90 |
Correct |
30 ms |
33788 KB |
Output is correct |
91 |
Correct |
32 ms |
33780 KB |
Output is correct |
92 |
Correct |
33 ms |
33952 KB |
Output is correct |
93 |
Correct |
33 ms |
33788 KB |
Output is correct |
94 |
Correct |
33 ms |
33748 KB |
Output is correct |
95 |
Correct |
33 ms |
33808 KB |
Output is correct |
96 |
Correct |
33 ms |
33788 KB |
Output is correct |
97 |
Correct |
34 ms |
33788 KB |
Output is correct |
98 |
Correct |
33 ms |
33808 KB |
Output is correct |
99 |
Correct |
33 ms |
33868 KB |
Output is correct |
100 |
Correct |
33 ms |
33856 KB |
Output is correct |
101 |
Correct |
34 ms |
33792 KB |
Output is correct |
102 |
Correct |
34 ms |
33792 KB |
Output is correct |