Submission #108120

# Submission time Handle Problem Language Result Execution time Memory
108120 2019-04-27T13:53:27 Z hugo_pm Lamps (JOI19_lamps) C++17
100 / 100
163 ms 67188 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

const int borne = 1000*1000 + 5;
int dp[borne][2][3];
int len;
int cur[borne];
int cible[borne];

void calc(int dep, int isToggle, int set)
{
	int &rep = dp[dep][isToggle][set];
	rep = BIG;
	if (dep) {
		int vc = cur[dep];
		if (set < 2) vc = set;
		if (isToggle) vc ^= 1;
		if (vc != cible[dep]) { rep = BIG; return; }
	}
	
	if (dep == len) { rep = 0; return; }

	form(newTog, 2) form(newSet, 3) {
		int cx = dp[dep+1][newTog][newSet];
		if (newTog == 1 && isToggle == 0) ++cx;
		if (newSet != set && newSet != 2) ++cx;
		chmin(rep, cx);
	}
}

void solve()
{
	cin >> len;
	string s, t;
	cin >> s >> t;
	form(i, len) cur[i+1] = (s[i] == '0' ? 0 : 1);
	form(i, len) cible[i+1] = (t[i] == '0' ? 0 : 1);

	ford(i, len) form(a, 2) form(b, 3) calc(i+1,a,b);
	calc(0, 0, 2);
	cout << dp[0][0][2] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 356 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 356 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 4 ms 600 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 560 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 524 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
57 Correct 3 ms 512 KB Output is correct
58 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 428 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 112 ms 64988 KB Output is correct
8 Correct 126 ms 64976 KB Output is correct
9 Correct 127 ms 65096 KB Output is correct
10 Correct 127 ms 65100 KB Output is correct
11 Correct 139 ms 65036 KB Output is correct
12 Correct 130 ms 65164 KB Output is correct
13 Correct 127 ms 65004 KB Output is correct
14 Correct 146 ms 65096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 356 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 4 ms 600 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 560 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 524 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
57 Correct 3 ms 512 KB Output is correct
58 Correct 2 ms 512 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 2 ms 428 KB Output is correct
61 Correct 2 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 112 ms 64988 KB Output is correct
66 Correct 126 ms 64976 KB Output is correct
67 Correct 127 ms 65096 KB Output is correct
68 Correct 127 ms 65100 KB Output is correct
69 Correct 139 ms 65036 KB Output is correct
70 Correct 130 ms 65164 KB Output is correct
71 Correct 127 ms 65004 KB Output is correct
72 Correct 146 ms 65096 KB Output is correct
73 Correct 153 ms 66908 KB Output is correct
74 Correct 141 ms 67020 KB Output is correct
75 Correct 138 ms 67188 KB Output is correct
76 Correct 115 ms 67016 KB Output is correct
77 Correct 124 ms 66968 KB Output is correct
78 Correct 126 ms 67120 KB Output is correct
79 Correct 119 ms 67000 KB Output is correct
80 Correct 142 ms 67044 KB Output is correct
81 Correct 128 ms 67016 KB Output is correct
82 Correct 131 ms 67188 KB Output is correct
83 Correct 137 ms 66924 KB Output is correct
84 Correct 140 ms 67012 KB Output is correct
85 Correct 118 ms 67016 KB Output is correct
86 Correct 129 ms 67012 KB Output is correct
87 Correct 136 ms 66996 KB Output is correct
88 Correct 120 ms 67140 KB Output is correct
89 Correct 129 ms 67016 KB Output is correct
90 Correct 135 ms 67012 KB Output is correct
91 Correct 117 ms 67020 KB Output is correct
92 Correct 123 ms 67088 KB Output is correct
93 Correct 163 ms 67016 KB Output is correct
94 Correct 116 ms 67020 KB Output is correct
95 Correct 111 ms 67016 KB Output is correct
96 Correct 122 ms 67144 KB Output is correct
97 Correct 145 ms 67016 KB Output is correct
98 Correct 132 ms 66988 KB Output is correct
99 Correct 142 ms 66992 KB Output is correct
100 Correct 131 ms 67100 KB Output is correct
101 Correct 120 ms 67016 KB Output is correct
102 Correct 126 ms 67020 KB Output is correct