/*
ID: varunra2
LANG: C++
TASK: lamps
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif
#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second
const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
VI conv(string a) {
VI ret;
ret.PB(0);
trav(x, a) {
if (x == '0')
ret.PB(0);
else
ret.PB(1);
}
return ret;
}
int calc(int j, int k, int val) {
if (j == 1) val = 0;
if (j == 2) val = 1;
if (k) val ^= 1;
return val;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("lamps.in", "r", stdin);
// freopen("lamps.out", "w", stdout);
// #endif
cin.sync_with_stdio(0);
cin.tie(0);
int n;
string a, b;
cin >> n;
cin >> a >> b;
n++;
auto va = conv(a);
auto vb = conv(b);
vector<VVI> dp(n, VVI(3, VI(2, INF)));
dp[0][0][0] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 2; k++) {
if (calc(j, k, va[i]) == vb[i]) {
for (int l = 0; l < 3; l++) {
for (int m = 0; m < 2; m++) {
int cost1 = 0;
if (j != 0 and l != j) cost1 = 1;
int cost2 = 0;
if (k == 1 and m == 0) cost2 = 1;
dp[i][j][k] = min(dp[i][j][k], dp[i - 1][l][m] + cost1 + cost2);
}
}
}
}
}
}
int ret = INF;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
ret = min(ret, dp[n - 1][i][j]);
}
}
cout << ret << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
392 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
396 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
236 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
392 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
396 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
236 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
748 KB |
Output is correct |
36 |
Correct |
1 ms |
748 KB |
Output is correct |
37 |
Correct |
1 ms |
748 KB |
Output is correct |
38 |
Correct |
1 ms |
748 KB |
Output is correct |
39 |
Correct |
1 ms |
748 KB |
Output is correct |
40 |
Correct |
2 ms |
748 KB |
Output is correct |
41 |
Correct |
1 ms |
748 KB |
Output is correct |
42 |
Correct |
2 ms |
748 KB |
Output is correct |
43 |
Correct |
2 ms |
748 KB |
Output is correct |
44 |
Correct |
1 ms |
748 KB |
Output is correct |
45 |
Correct |
2 ms |
748 KB |
Output is correct |
46 |
Correct |
1 ms |
748 KB |
Output is correct |
47 |
Correct |
1 ms |
748 KB |
Output is correct |
48 |
Correct |
1 ms |
748 KB |
Output is correct |
49 |
Correct |
1 ms |
748 KB |
Output is correct |
50 |
Correct |
2 ms |
748 KB |
Output is correct |
51 |
Correct |
2 ms |
748 KB |
Output is correct |
52 |
Correct |
1 ms |
748 KB |
Output is correct |
53 |
Correct |
1 ms |
748 KB |
Output is correct |
54 |
Correct |
1 ms |
748 KB |
Output is correct |
55 |
Correct |
1 ms |
748 KB |
Output is correct |
56 |
Correct |
1 ms |
748 KB |
Output is correct |
57 |
Correct |
1 ms |
748 KB |
Output is correct |
58 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
360 ms |
207956 KB |
Output is correct |
8 |
Correct |
359 ms |
207892 KB |
Output is correct |
9 |
Correct |
377 ms |
207956 KB |
Output is correct |
10 |
Correct |
362 ms |
207828 KB |
Output is correct |
11 |
Correct |
360 ms |
207780 KB |
Output is correct |
12 |
Correct |
352 ms |
207928 KB |
Output is correct |
13 |
Correct |
358 ms |
207764 KB |
Output is correct |
14 |
Correct |
360 ms |
207828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
392 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
396 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
236 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
748 KB |
Output is correct |
36 |
Correct |
1 ms |
748 KB |
Output is correct |
37 |
Correct |
1 ms |
748 KB |
Output is correct |
38 |
Correct |
1 ms |
748 KB |
Output is correct |
39 |
Correct |
1 ms |
748 KB |
Output is correct |
40 |
Correct |
2 ms |
748 KB |
Output is correct |
41 |
Correct |
1 ms |
748 KB |
Output is correct |
42 |
Correct |
2 ms |
748 KB |
Output is correct |
43 |
Correct |
2 ms |
748 KB |
Output is correct |
44 |
Correct |
1 ms |
748 KB |
Output is correct |
45 |
Correct |
2 ms |
748 KB |
Output is correct |
46 |
Correct |
1 ms |
748 KB |
Output is correct |
47 |
Correct |
1 ms |
748 KB |
Output is correct |
48 |
Correct |
1 ms |
748 KB |
Output is correct |
49 |
Correct |
1 ms |
748 KB |
Output is correct |
50 |
Correct |
2 ms |
748 KB |
Output is correct |
51 |
Correct |
2 ms |
748 KB |
Output is correct |
52 |
Correct |
1 ms |
748 KB |
Output is correct |
53 |
Correct |
1 ms |
748 KB |
Output is correct |
54 |
Correct |
1 ms |
748 KB |
Output is correct |
55 |
Correct |
1 ms |
748 KB |
Output is correct |
56 |
Correct |
1 ms |
748 KB |
Output is correct |
57 |
Correct |
1 ms |
748 KB |
Output is correct |
58 |
Correct |
2 ms |
748 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
360 ms |
207956 KB |
Output is correct |
66 |
Correct |
359 ms |
207892 KB |
Output is correct |
67 |
Correct |
377 ms |
207956 KB |
Output is correct |
68 |
Correct |
362 ms |
207828 KB |
Output is correct |
69 |
Correct |
360 ms |
207780 KB |
Output is correct |
70 |
Correct |
352 ms |
207928 KB |
Output is correct |
71 |
Correct |
358 ms |
207764 KB |
Output is correct |
72 |
Correct |
360 ms |
207828 KB |
Output is correct |
73 |
Correct |
355 ms |
207828 KB |
Output is correct |
74 |
Correct |
362 ms |
207904 KB |
Output is correct |
75 |
Correct |
362 ms |
207892 KB |
Output is correct |
76 |
Correct |
366 ms |
207828 KB |
Output is correct |
77 |
Correct |
356 ms |
207828 KB |
Output is correct |
78 |
Correct |
356 ms |
207956 KB |
Output is correct |
79 |
Correct |
353 ms |
207828 KB |
Output is correct |
80 |
Correct |
362 ms |
207828 KB |
Output is correct |
81 |
Correct |
381 ms |
207956 KB |
Output is correct |
82 |
Correct |
355 ms |
207956 KB |
Output is correct |
83 |
Correct |
365 ms |
207828 KB |
Output is correct |
84 |
Correct |
366 ms |
207956 KB |
Output is correct |
85 |
Correct |
363 ms |
207956 KB |
Output is correct |
86 |
Correct |
362 ms |
207956 KB |
Output is correct |
87 |
Correct |
362 ms |
207828 KB |
Output is correct |
88 |
Correct |
367 ms |
207828 KB |
Output is correct |
89 |
Correct |
363 ms |
207828 KB |
Output is correct |
90 |
Correct |
364 ms |
207828 KB |
Output is correct |
91 |
Correct |
369 ms |
207828 KB |
Output is correct |
92 |
Correct |
373 ms |
207852 KB |
Output is correct |
93 |
Correct |
368 ms |
207828 KB |
Output is correct |
94 |
Correct |
370 ms |
207828 KB |
Output is correct |
95 |
Correct |
371 ms |
207828 KB |
Output is correct |
96 |
Correct |
384 ms |
207976 KB |
Output is correct |
97 |
Correct |
369 ms |
207956 KB |
Output is correct |
98 |
Correct |
381 ms |
207892 KB |
Output is correct |
99 |
Correct |
371 ms |
207828 KB |
Output is correct |
100 |
Correct |
368 ms |
207828 KB |
Output is correct |
101 |
Correct |
372 ms |
207828 KB |
Output is correct |
102 |
Correct |
373 ms |
207828 KB |
Output is correct |