Submission #102520

# Submission time Handle Problem Language Result Execution time Memory
102520 2019-03-25T15:52:43 Z Bruteforceman Lamps (JOI19_lamps) C++11
100 / 100
419 ms 120340 KB
#include "bits/stdc++.h"
using namespace std;
string s, t;
int n;
const int inf = 1e9;

int mem[2][3][1000010];

int dp(int cur, int xr, int col) {
	if(cur == n) return 0;
	int &ans = mem[xr][col][cur];
	if(ans != -1) return ans;
	ans = inf;
	for(int i = 0; i < 2; i++) {
		for(int j = 0; j < 3; j++) {
			int cost = 0;
			if(xr != i && i > 0) ++cost;
			if(col != j && j > 0) ++cost;
			int c = (j > 0) ? (j - 1) : (t[cur] - '0');
			c ^= i;
			if(c == (s[cur] - '0')) {
				ans = min(ans, dp(cur + 1, i, j) + cost);
			} 
		}
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	memset(mem, -1, sizeof mem);
	cin >> n >> t >> s;
	cout << dp(0, 0, 0) << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23808 KB Output is correct
2 Correct 22 ms 23808 KB Output is correct
3 Correct 22 ms 23808 KB Output is correct
4 Correct 24 ms 23808 KB Output is correct
5 Correct 22 ms 23808 KB Output is correct
6 Correct 22 ms 23780 KB Output is correct
7 Correct 22 ms 23808 KB Output is correct
8 Correct 22 ms 23808 KB Output is correct
9 Correct 22 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 25 ms 23800 KB Output is correct
14 Correct 21 ms 23800 KB Output is correct
15 Correct 22 ms 23808 KB Output is correct
16 Correct 24 ms 23808 KB Output is correct
17 Correct 24 ms 23936 KB Output is correct
18 Correct 21 ms 23808 KB Output is correct
19 Correct 21 ms 23808 KB Output is correct
20 Correct 23 ms 23808 KB Output is correct
21 Correct 25 ms 23808 KB Output is correct
22 Correct 22 ms 23808 KB Output is correct
23 Correct 24 ms 23808 KB Output is correct
24 Correct 23 ms 23796 KB Output is correct
25 Correct 16 ms 23808 KB Output is correct
26 Correct 25 ms 23808 KB Output is correct
27 Correct 22 ms 23808 KB Output is correct
28 Correct 23 ms 23808 KB Output is correct
29 Correct 21 ms 23808 KB Output is correct
30 Correct 25 ms 23780 KB Output is correct
31 Correct 22 ms 23808 KB Output is correct
32 Correct 22 ms 23808 KB Output is correct
33 Correct 23 ms 23800 KB Output is correct
34 Correct 26 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23808 KB Output is correct
2 Correct 22 ms 23808 KB Output is correct
3 Correct 22 ms 23808 KB Output is correct
4 Correct 24 ms 23808 KB Output is correct
5 Correct 22 ms 23808 KB Output is correct
6 Correct 22 ms 23780 KB Output is correct
7 Correct 22 ms 23808 KB Output is correct
8 Correct 22 ms 23808 KB Output is correct
9 Correct 22 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 25 ms 23800 KB Output is correct
14 Correct 21 ms 23800 KB Output is correct
15 Correct 22 ms 23808 KB Output is correct
16 Correct 24 ms 23808 KB Output is correct
17 Correct 24 ms 23936 KB Output is correct
18 Correct 21 ms 23808 KB Output is correct
19 Correct 21 ms 23808 KB Output is correct
20 Correct 23 ms 23808 KB Output is correct
21 Correct 25 ms 23808 KB Output is correct
22 Correct 22 ms 23808 KB Output is correct
23 Correct 24 ms 23808 KB Output is correct
24 Correct 23 ms 23796 KB Output is correct
25 Correct 16 ms 23808 KB Output is correct
26 Correct 25 ms 23808 KB Output is correct
27 Correct 22 ms 23808 KB Output is correct
28 Correct 23 ms 23808 KB Output is correct
29 Correct 21 ms 23808 KB Output is correct
30 Correct 25 ms 23780 KB Output is correct
31 Correct 22 ms 23808 KB Output is correct
32 Correct 22 ms 23808 KB Output is correct
33 Correct 23 ms 23800 KB Output is correct
34 Correct 26 ms 23808 KB Output is correct
35 Correct 25 ms 23936 KB Output is correct
36 Correct 25 ms 23948 KB Output is correct
37 Correct 22 ms 24064 KB Output is correct
38 Correct 22 ms 23928 KB Output is correct
39 Correct 27 ms 24056 KB Output is correct
40 Correct 27 ms 24064 KB Output is correct
41 Correct 25 ms 24064 KB Output is correct
42 Correct 25 ms 24064 KB Output is correct
43 Correct 23 ms 24064 KB Output is correct
44 Correct 23 ms 24056 KB Output is correct
45 Correct 23 ms 23936 KB Output is correct
46 Correct 24 ms 24076 KB Output is correct
47 Correct 24 ms 24064 KB Output is correct
48 Correct 23 ms 24064 KB Output is correct
49 Correct 26 ms 23936 KB Output is correct
50 Correct 22 ms 24064 KB Output is correct
51 Correct 22 ms 24056 KB Output is correct
52 Correct 22 ms 23936 KB Output is correct
53 Correct 24 ms 23936 KB Output is correct
54 Correct 23 ms 24064 KB Output is correct
55 Correct 23 ms 23936 KB Output is correct
56 Correct 25 ms 24064 KB Output is correct
57 Correct 23 ms 24064 KB Output is correct
58 Correct 23 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23728 KB Output is correct
2 Correct 22 ms 23780 KB Output is correct
3 Correct 25 ms 23928 KB Output is correct
4 Correct 22 ms 23808 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 24 ms 23816 KB Output is correct
7 Correct 311 ms 120224 KB Output is correct
8 Correct 380 ms 120164 KB Output is correct
9 Correct 335 ms 120224 KB Output is correct
10 Correct 355 ms 120168 KB Output is correct
11 Correct 328 ms 120136 KB Output is correct
12 Correct 343 ms 120036 KB Output is correct
13 Correct 297 ms 120232 KB Output is correct
14 Correct 321 ms 120168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23808 KB Output is correct
2 Correct 22 ms 23808 KB Output is correct
3 Correct 22 ms 23808 KB Output is correct
4 Correct 24 ms 23808 KB Output is correct
5 Correct 22 ms 23808 KB Output is correct
6 Correct 22 ms 23780 KB Output is correct
7 Correct 22 ms 23808 KB Output is correct
8 Correct 22 ms 23808 KB Output is correct
9 Correct 22 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 25 ms 23800 KB Output is correct
14 Correct 21 ms 23800 KB Output is correct
15 Correct 22 ms 23808 KB Output is correct
16 Correct 24 ms 23808 KB Output is correct
17 Correct 24 ms 23936 KB Output is correct
18 Correct 21 ms 23808 KB Output is correct
19 Correct 21 ms 23808 KB Output is correct
20 Correct 23 ms 23808 KB Output is correct
21 Correct 25 ms 23808 KB Output is correct
22 Correct 22 ms 23808 KB Output is correct
23 Correct 24 ms 23808 KB Output is correct
24 Correct 23 ms 23796 KB Output is correct
25 Correct 16 ms 23808 KB Output is correct
26 Correct 25 ms 23808 KB Output is correct
27 Correct 22 ms 23808 KB Output is correct
28 Correct 23 ms 23808 KB Output is correct
29 Correct 21 ms 23808 KB Output is correct
30 Correct 25 ms 23780 KB Output is correct
31 Correct 22 ms 23808 KB Output is correct
32 Correct 22 ms 23808 KB Output is correct
33 Correct 23 ms 23800 KB Output is correct
34 Correct 26 ms 23808 KB Output is correct
35 Correct 25 ms 23936 KB Output is correct
36 Correct 25 ms 23948 KB Output is correct
37 Correct 22 ms 24064 KB Output is correct
38 Correct 22 ms 23928 KB Output is correct
39 Correct 27 ms 24056 KB Output is correct
40 Correct 27 ms 24064 KB Output is correct
41 Correct 25 ms 24064 KB Output is correct
42 Correct 25 ms 24064 KB Output is correct
43 Correct 23 ms 24064 KB Output is correct
44 Correct 23 ms 24056 KB Output is correct
45 Correct 23 ms 23936 KB Output is correct
46 Correct 24 ms 24076 KB Output is correct
47 Correct 24 ms 24064 KB Output is correct
48 Correct 23 ms 24064 KB Output is correct
49 Correct 26 ms 23936 KB Output is correct
50 Correct 22 ms 24064 KB Output is correct
51 Correct 22 ms 24056 KB Output is correct
52 Correct 22 ms 23936 KB Output is correct
53 Correct 24 ms 23936 KB Output is correct
54 Correct 23 ms 24064 KB Output is correct
55 Correct 23 ms 23936 KB Output is correct
56 Correct 25 ms 24064 KB Output is correct
57 Correct 23 ms 24064 KB Output is correct
58 Correct 23 ms 23936 KB Output is correct
59 Correct 21 ms 23728 KB Output is correct
60 Correct 22 ms 23780 KB Output is correct
61 Correct 25 ms 23928 KB Output is correct
62 Correct 22 ms 23808 KB Output is correct
63 Correct 23 ms 23928 KB Output is correct
64 Correct 24 ms 23816 KB Output is correct
65 Correct 311 ms 120224 KB Output is correct
66 Correct 380 ms 120164 KB Output is correct
67 Correct 335 ms 120224 KB Output is correct
68 Correct 355 ms 120168 KB Output is correct
69 Correct 328 ms 120136 KB Output is correct
70 Correct 343 ms 120036 KB Output is correct
71 Correct 297 ms 120232 KB Output is correct
72 Correct 321 ms 120168 KB Output is correct
73 Correct 317 ms 120160 KB Output is correct
74 Correct 305 ms 120036 KB Output is correct
75 Correct 397 ms 120044 KB Output is correct
76 Correct 316 ms 120036 KB Output is correct
77 Correct 364 ms 120120 KB Output is correct
78 Correct 336 ms 120036 KB Output is correct
79 Correct 321 ms 120012 KB Output is correct
80 Correct 371 ms 120164 KB Output is correct
81 Correct 335 ms 120236 KB Output is correct
82 Correct 338 ms 120172 KB Output is correct
83 Correct 329 ms 120340 KB Output is correct
84 Correct 310 ms 120160 KB Output is correct
85 Correct 320 ms 120164 KB Output is correct
86 Correct 284 ms 120284 KB Output is correct
87 Correct 378 ms 120232 KB Output is correct
88 Correct 318 ms 120200 KB Output is correct
89 Correct 266 ms 120100 KB Output is correct
90 Correct 272 ms 120164 KB Output is correct
91 Correct 350 ms 120040 KB Output is correct
92 Correct 332 ms 120240 KB Output is correct
93 Correct 306 ms 120136 KB Output is correct
94 Correct 328 ms 120036 KB Output is correct
95 Correct 320 ms 120128 KB Output is correct
96 Correct 313 ms 120108 KB Output is correct
97 Correct 338 ms 120172 KB Output is correct
98 Correct 294 ms 120036 KB Output is correct
99 Correct 349 ms 120168 KB Output is correct
100 Correct 418 ms 120036 KB Output is correct
101 Correct 419 ms 120164 KB Output is correct
102 Correct 318 ms 120036 KB Output is correct