#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;
#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<
#define fi first
#define sec second
#define mp make_pair
#define pb push_back
const int MAXN = 1000010;
const int inf = 2000000;
int n;
char s[MAXN], p[MAXN];
int dp[MAXN][4][4][4];
vector <pair <lf, int> > tmp;
void normal(vector <lf> &v) {
tmp.clear();
REP(i, 3) tmp.pb({v[i], i});
sort(all(tmp));
int cnt = 1;
REP(i, 3) {
if (tmp[i].fi) v[tmp[i].sec] = cnt++;
}
}
int rek(int i, vector <lf> v) {
normal(v);
int a = v[0], b = v[1], c = v[2];
if (i == n + 1) return 0;
if (dp[i][a][b][c] != -1) return dp[i][a][b][c];
int ret = inf;
int t = s[i];
if (b && b > c && b > a) t = 0;
if (c && c > b && c > a) t = 1;
if (a && a > b && a > c) {
if (b && b > c) t = 1;
if (c && c > b) t = 0;
if (!b && !c) t = s[i] ^ 1;
}
if (a && b && c && t != p[i]) return dp[i][a][b][c] = inf;
if (!a) {
for (lf x = 0.5; x <= 3; x += 0.5) {
ret = min(ret, rek(i, {x, b, c}) + 1);
}
}
if (!b) {
for (lf x = 0.5; x <= 3; x += 0.5) {
ret = min(ret, rek(i, {a, x, c}) + 1);
}
}
if (!c) {
for (lf x = 0.5; x <= 3; x += 0.5) {
ret = min(ret, rek(i, {a, b, x}) + 1);
}
}
if (t == p[i]) {
ret = min(ret, rek(i + 1, {a, b, c}));
ret = min(ret, rek(i + 1, {0, b, c}));
ret = min(ret, rek(i + 1, {0, 0, c}));
ret = min(ret, rek(i + 1, {0, 0, 0}));
ret = min(ret, rek(i + 1, {a, 0, c}));
ret = min(ret, rek(i + 1, {a, b, 0}));
ret = min(ret, rek(i + 1, {a, 0, 0}));
ret = min(ret, rek(i + 1, {0, b, 0}));
}
return dp[i][a][b][c] = ret;
}
int main() {
cin >> n;
cin >> s >> p;
REP(i, n) {
s[i] -= '0';
p[i] -= '0';
}
for (int i = n; i > 0; i--) {
s[i] = s[i - 1];
p[i] = p[i - 1];
}
memset(dp, -1, sizeof dp);
cout << rek(1, {0, 0, 0}) << endl;
//FOR(i, 1, n + 1) TRACE(i _ rek(i, {0, 0, 0}));
return 0;
}
Compilation message
lamp.cpp: In function 'int rek(int, std::vector<double>)':
lamp.cpp:64:38: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i, {x, b, c}) + 1);
^
lamp.cpp:64:38: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:64:38: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:64:38: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:69:38: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i, {a, x, c}) + 1);
^
lamp.cpp:69:38: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:69:38: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:69:38: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:74:38: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i, {a, b, x}) + 1);
^
lamp.cpp:74:38: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:74:38: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:74:38: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:79:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i + 1, {a, b, c}));
^
lamp.cpp:79:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:79:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:79:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:79:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:79:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:80:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i + 1, {0, b, c}));
^
lamp.cpp:80:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:80:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:80:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:81:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i + 1, {0, 0, c}));
^
lamp.cpp:81:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:83:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i + 1, {a, 0, c}));
^
lamp.cpp:83:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:83:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:83:40: warning: narrowing conversion of 'c' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:84:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i + 1, {a, b, 0}));
^
lamp.cpp:84:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:84:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:84:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:85:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i + 1, {a, 0, 0}));
^
lamp.cpp:85:40: warning: narrowing conversion of 'a' from 'int' to 'double' inside { } [-Wnarrowing]
lamp.cpp:86:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
ret = min(ret, rek(i + 1, {0, b, 0}));
^
lamp.cpp:86:40: warning: narrowing conversion of 'b' from 'int' to 'double' inside { } [-Wnarrowing]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
250744 KB |
Output is correct |
2 |
Correct |
143 ms |
250872 KB |
Output is correct |
3 |
Correct |
133 ms |
250744 KB |
Output is correct |
4 |
Correct |
142 ms |
250744 KB |
Output is correct |
5 |
Correct |
129 ms |
250744 KB |
Output is correct |
6 |
Correct |
132 ms |
250848 KB |
Output is correct |
7 |
Correct |
129 ms |
250872 KB |
Output is correct |
8 |
Correct |
128 ms |
250876 KB |
Output is correct |
9 |
Correct |
129 ms |
250780 KB |
Output is correct |
10 |
Correct |
130 ms |
250824 KB |
Output is correct |
11 |
Correct |
131 ms |
250744 KB |
Output is correct |
12 |
Correct |
129 ms |
250744 KB |
Output is correct |
13 |
Correct |
128 ms |
250872 KB |
Output is correct |
14 |
Correct |
127 ms |
250852 KB |
Output is correct |
15 |
Correct |
127 ms |
251000 KB |
Output is correct |
16 |
Correct |
131 ms |
250744 KB |
Output is correct |
17 |
Correct |
130 ms |
250872 KB |
Output is correct |
18 |
Correct |
133 ms |
250864 KB |
Output is correct |
19 |
Correct |
127 ms |
250868 KB |
Output is correct |
20 |
Correct |
128 ms |
250872 KB |
Output is correct |
21 |
Correct |
130 ms |
250800 KB |
Output is correct |
22 |
Correct |
131 ms |
250860 KB |
Output is correct |
23 |
Correct |
127 ms |
250756 KB |
Output is correct |
24 |
Correct |
133 ms |
250840 KB |
Output is correct |
25 |
Correct |
129 ms |
250812 KB |
Output is correct |
26 |
Correct |
129 ms |
250744 KB |
Output is correct |
27 |
Correct |
130 ms |
250872 KB |
Output is correct |
28 |
Correct |
129 ms |
250760 KB |
Output is correct |
29 |
Correct |
129 ms |
250872 KB |
Output is correct |
30 |
Correct |
128 ms |
250904 KB |
Output is correct |
31 |
Correct |
131 ms |
250872 KB |
Output is correct |
32 |
Correct |
130 ms |
250744 KB |
Output is correct |
33 |
Correct |
130 ms |
250904 KB |
Output is correct |
34 |
Correct |
128 ms |
250744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
250744 KB |
Output is correct |
2 |
Correct |
143 ms |
250872 KB |
Output is correct |
3 |
Correct |
133 ms |
250744 KB |
Output is correct |
4 |
Correct |
142 ms |
250744 KB |
Output is correct |
5 |
Correct |
129 ms |
250744 KB |
Output is correct |
6 |
Correct |
132 ms |
250848 KB |
Output is correct |
7 |
Correct |
129 ms |
250872 KB |
Output is correct |
8 |
Correct |
128 ms |
250876 KB |
Output is correct |
9 |
Correct |
129 ms |
250780 KB |
Output is correct |
10 |
Correct |
130 ms |
250824 KB |
Output is correct |
11 |
Correct |
131 ms |
250744 KB |
Output is correct |
12 |
Correct |
129 ms |
250744 KB |
Output is correct |
13 |
Correct |
128 ms |
250872 KB |
Output is correct |
14 |
Correct |
127 ms |
250852 KB |
Output is correct |
15 |
Correct |
127 ms |
251000 KB |
Output is correct |
16 |
Correct |
131 ms |
250744 KB |
Output is correct |
17 |
Correct |
130 ms |
250872 KB |
Output is correct |
18 |
Correct |
133 ms |
250864 KB |
Output is correct |
19 |
Correct |
127 ms |
250868 KB |
Output is correct |
20 |
Correct |
128 ms |
250872 KB |
Output is correct |
21 |
Correct |
130 ms |
250800 KB |
Output is correct |
22 |
Correct |
131 ms |
250860 KB |
Output is correct |
23 |
Correct |
127 ms |
250756 KB |
Output is correct |
24 |
Correct |
133 ms |
250840 KB |
Output is correct |
25 |
Correct |
129 ms |
250812 KB |
Output is correct |
26 |
Correct |
129 ms |
250744 KB |
Output is correct |
27 |
Correct |
130 ms |
250872 KB |
Output is correct |
28 |
Correct |
129 ms |
250760 KB |
Output is correct |
29 |
Correct |
129 ms |
250872 KB |
Output is correct |
30 |
Correct |
128 ms |
250904 KB |
Output is correct |
31 |
Correct |
131 ms |
250872 KB |
Output is correct |
32 |
Correct |
130 ms |
250744 KB |
Output is correct |
33 |
Correct |
130 ms |
250904 KB |
Output is correct |
34 |
Correct |
128 ms |
250744 KB |
Output is correct |
35 |
Correct |
181 ms |
251740 KB |
Output is correct |
36 |
Correct |
160 ms |
251768 KB |
Output is correct |
37 |
Correct |
162 ms |
251768 KB |
Output is correct |
38 |
Correct |
164 ms |
251768 KB |
Output is correct |
39 |
Correct |
161 ms |
251256 KB |
Output is correct |
40 |
Correct |
168 ms |
251384 KB |
Output is correct |
41 |
Correct |
165 ms |
251256 KB |
Output is correct |
42 |
Correct |
159 ms |
251256 KB |
Output is correct |
43 |
Correct |
159 ms |
251256 KB |
Output is correct |
44 |
Correct |
159 ms |
251384 KB |
Output is correct |
45 |
Correct |
163 ms |
251384 KB |
Output is correct |
46 |
Correct |
161 ms |
251384 KB |
Output is correct |
47 |
Correct |
171 ms |
251384 KB |
Output is correct |
48 |
Correct |
164 ms |
251512 KB |
Output is correct |
49 |
Correct |
161 ms |
251516 KB |
Output is correct |
50 |
Correct |
176 ms |
251512 KB |
Output is correct |
51 |
Correct |
167 ms |
251512 KB |
Output is correct |
52 |
Correct |
160 ms |
251452 KB |
Output is correct |
53 |
Correct |
161 ms |
251512 KB |
Output is correct |
54 |
Correct |
161 ms |
251536 KB |
Output is correct |
55 |
Correct |
161 ms |
251464 KB |
Output is correct |
56 |
Correct |
182 ms |
251512 KB |
Output is correct |
57 |
Correct |
172 ms |
251512 KB |
Output is correct |
58 |
Correct |
161 ms |
251640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
250744 KB |
Output is correct |
2 |
Correct |
128 ms |
250744 KB |
Output is correct |
3 |
Correct |
129 ms |
250872 KB |
Output is correct |
4 |
Correct |
126 ms |
250744 KB |
Output is correct |
5 |
Correct |
127 ms |
250960 KB |
Output is correct |
6 |
Correct |
128 ms |
250744 KB |
Output is correct |
7 |
Runtime error |
248 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
250744 KB |
Output is correct |
2 |
Correct |
143 ms |
250872 KB |
Output is correct |
3 |
Correct |
133 ms |
250744 KB |
Output is correct |
4 |
Correct |
142 ms |
250744 KB |
Output is correct |
5 |
Correct |
129 ms |
250744 KB |
Output is correct |
6 |
Correct |
132 ms |
250848 KB |
Output is correct |
7 |
Correct |
129 ms |
250872 KB |
Output is correct |
8 |
Correct |
128 ms |
250876 KB |
Output is correct |
9 |
Correct |
129 ms |
250780 KB |
Output is correct |
10 |
Correct |
130 ms |
250824 KB |
Output is correct |
11 |
Correct |
131 ms |
250744 KB |
Output is correct |
12 |
Correct |
129 ms |
250744 KB |
Output is correct |
13 |
Correct |
128 ms |
250872 KB |
Output is correct |
14 |
Correct |
127 ms |
250852 KB |
Output is correct |
15 |
Correct |
127 ms |
251000 KB |
Output is correct |
16 |
Correct |
131 ms |
250744 KB |
Output is correct |
17 |
Correct |
130 ms |
250872 KB |
Output is correct |
18 |
Correct |
133 ms |
250864 KB |
Output is correct |
19 |
Correct |
127 ms |
250868 KB |
Output is correct |
20 |
Correct |
128 ms |
250872 KB |
Output is correct |
21 |
Correct |
130 ms |
250800 KB |
Output is correct |
22 |
Correct |
131 ms |
250860 KB |
Output is correct |
23 |
Correct |
127 ms |
250756 KB |
Output is correct |
24 |
Correct |
133 ms |
250840 KB |
Output is correct |
25 |
Correct |
129 ms |
250812 KB |
Output is correct |
26 |
Correct |
129 ms |
250744 KB |
Output is correct |
27 |
Correct |
130 ms |
250872 KB |
Output is correct |
28 |
Correct |
129 ms |
250760 KB |
Output is correct |
29 |
Correct |
129 ms |
250872 KB |
Output is correct |
30 |
Correct |
128 ms |
250904 KB |
Output is correct |
31 |
Correct |
131 ms |
250872 KB |
Output is correct |
32 |
Correct |
130 ms |
250744 KB |
Output is correct |
33 |
Correct |
130 ms |
250904 KB |
Output is correct |
34 |
Correct |
128 ms |
250744 KB |
Output is correct |
35 |
Correct |
181 ms |
251740 KB |
Output is correct |
36 |
Correct |
160 ms |
251768 KB |
Output is correct |
37 |
Correct |
162 ms |
251768 KB |
Output is correct |
38 |
Correct |
164 ms |
251768 KB |
Output is correct |
39 |
Correct |
161 ms |
251256 KB |
Output is correct |
40 |
Correct |
168 ms |
251384 KB |
Output is correct |
41 |
Correct |
165 ms |
251256 KB |
Output is correct |
42 |
Correct |
159 ms |
251256 KB |
Output is correct |
43 |
Correct |
159 ms |
251256 KB |
Output is correct |
44 |
Correct |
159 ms |
251384 KB |
Output is correct |
45 |
Correct |
163 ms |
251384 KB |
Output is correct |
46 |
Correct |
161 ms |
251384 KB |
Output is correct |
47 |
Correct |
171 ms |
251384 KB |
Output is correct |
48 |
Correct |
164 ms |
251512 KB |
Output is correct |
49 |
Correct |
161 ms |
251516 KB |
Output is correct |
50 |
Correct |
176 ms |
251512 KB |
Output is correct |
51 |
Correct |
167 ms |
251512 KB |
Output is correct |
52 |
Correct |
160 ms |
251452 KB |
Output is correct |
53 |
Correct |
161 ms |
251512 KB |
Output is correct |
54 |
Correct |
161 ms |
251536 KB |
Output is correct |
55 |
Correct |
161 ms |
251464 KB |
Output is correct |
56 |
Correct |
182 ms |
251512 KB |
Output is correct |
57 |
Correct |
172 ms |
251512 KB |
Output is correct |
58 |
Correct |
161 ms |
251640 KB |
Output is correct |
59 |
Correct |
126 ms |
250744 KB |
Output is correct |
60 |
Correct |
128 ms |
250744 KB |
Output is correct |
61 |
Correct |
129 ms |
250872 KB |
Output is correct |
62 |
Correct |
126 ms |
250744 KB |
Output is correct |
63 |
Correct |
127 ms |
250960 KB |
Output is correct |
64 |
Correct |
128 ms |
250744 KB |
Output is correct |
65 |
Runtime error |
248 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
66 |
Halted |
0 ms |
0 KB |
- |