Submission #166219

# Submission time Handle Problem Language Result Execution time Memory
166219 2019-12-01T09:56:35 Z maruii Lamps (JOI19_lamps) C++14
100 / 100
204 ms 27948 KB
#include <bits/stdc++.h>
using namespace std;

char A[1000005], B[1000005];
int X[1000005][6];
int f(int x, int y) {
	return (x / 3 && y / 3 == 0) + (x % 3 != y % 3 && x % 3);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N; cin >> N;
	cin >> A + 1 >> B + 1;
	for (int i = 0; i <= N; ++i) fill(X[i], X[i] + 6, 1e9);
	X[0][0] = 0;
	for (int i = 1; i <= N; ++i) {
		int t = (A[i] - '0') << 1 | (B[i] - '0');
		if (t == 0) {
			for (int j = 0; j < 6; ++j) {
				X[i][0] = min(X[i][0], X[i - 1][j] + f(0, j));
				X[i][1] = min(X[i][1], X[i - 1][j] + f(1, j));
				X[i][5] = min(X[i][5], X[i - 1][j] + f(5, j));
			}
		}
		else if (t == 1) {
			for (int j = 0; j < 6; ++j) {
				X[i][3] = min(X[i][3], X[i - 1][j] + f(3, j));
				X[i][4] = min(X[i][4], X[i - 1][j] + f(4, j));
				X[i][2] = min(X[i][2], X[i - 1][j] + f(2, j));
			}
		}
		else if (t == 2) {
			for (int j = 0; j < 6; ++j) {
				X[i][3] = min(X[i][3], X[i - 1][j] + f(3, j));
				X[i][1] = min(X[i][1], X[i - 1][j] + f(1, j));
				X[i][5] = min(X[i][5], X[i - 1][j] + f(5, j));
			}
		}
		else {
			for (int j = 0; j < 6; ++j) {
				X[i][0] = min(X[i][0], X[i - 1][j] + f(0, j));
				X[i][4] = min(X[i][4], X[i - 1][j] + f(4, j));
				X[i][2] = min(X[i][2], X[i - 1][j] + f(2, j));
			}
		}
	}
	cout << *min_element(X[N], X[N] + 6);
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:13:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  cin >> A + 1 >> B + 1;
         ~~^~~
lamp.cpp:13:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  cin >> A + 1 >> B + 1;
                  ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 67 ms 27768 KB Output is correct
8 Correct 56 ms 27768 KB Output is correct
9 Correct 56 ms 27720 KB Output is correct
10 Correct 55 ms 27792 KB Output is correct
11 Correct 103 ms 27868 KB Output is correct
12 Correct 57 ms 27800 KB Output is correct
13 Correct 57 ms 27812 KB Output is correct
14 Correct 73 ms 27768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 380 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 67 ms 27768 KB Output is correct
66 Correct 56 ms 27768 KB Output is correct
67 Correct 56 ms 27720 KB Output is correct
68 Correct 55 ms 27792 KB Output is correct
69 Correct 103 ms 27868 KB Output is correct
70 Correct 57 ms 27800 KB Output is correct
71 Correct 57 ms 27812 KB Output is correct
72 Correct 73 ms 27768 KB Output is correct
73 Correct 54 ms 27768 KB Output is correct
74 Correct 55 ms 27768 KB Output is correct
75 Correct 58 ms 27948 KB Output is correct
76 Correct 58 ms 27816 KB Output is correct
77 Correct 56 ms 27812 KB Output is correct
78 Correct 56 ms 27768 KB Output is correct
79 Correct 63 ms 27740 KB Output is correct
80 Correct 56 ms 27768 KB Output is correct
81 Correct 57 ms 27720 KB Output is correct
82 Correct 56 ms 27896 KB Output is correct
83 Correct 62 ms 27768 KB Output is correct
84 Correct 62 ms 27768 KB Output is correct
85 Correct 62 ms 27920 KB Output is correct
86 Correct 61 ms 27772 KB Output is correct
87 Correct 62 ms 27796 KB Output is correct
88 Correct 69 ms 27896 KB Output is correct
89 Correct 62 ms 27788 KB Output is correct
90 Correct 62 ms 27868 KB Output is correct
91 Correct 64 ms 27772 KB Output is correct
92 Correct 64 ms 27792 KB Output is correct
93 Correct 65 ms 27768 KB Output is correct
94 Correct 64 ms 27740 KB Output is correct
95 Correct 204 ms 27768 KB Output is correct
96 Correct 66 ms 27768 KB Output is correct
97 Correct 68 ms 27768 KB Output is correct
98 Correct 66 ms 27768 KB Output is correct
99 Correct 65 ms 27772 KB Output is correct
100 Correct 66 ms 27768 KB Output is correct
101 Correct 65 ms 27768 KB Output is correct
102 Correct 66 ms 27772 KB Output is correct