# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
110512 | 2019-05-11T05:07:27 Z | AngusRitossa | Lamps (JOI19_lamps) | C++14 | 226 ms | 25948 KB |
#include <bits/stdc++.h> using namespace std; int memo[1000010][2], done[1000010][2], a[1000010], b[1000010], n, loopcost[1000010][2]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { char c; scanf(" %c", &c); a[i] = c-'0'; } for (int i = 0; i < n; i++) { char c; scanf(" %c", &c); b[i] = c-'0'; } for (int i = n-1; i >= 0; i--) { for (int t = 0; t < 2; t++) { loopcost[i][t] = 1e9; int ans = 1e9; if (a[i] == (b[i]^t)) { ans = min(ans, memo[i+1][t]); } else ans = min(ans, memo[i+1][!t] + !t); int extracost = 1, isok = 1, istoggled = t; if (i != n-1 && b[i+1] == b[i]) { loopcost[i][t] = memo[i+1][t]+1; loopcost[i][t] = min(loopcost[i][t], loopcost[i+1][t]); } else if (i != n-1 && b[i+1] != b[i]) { loopcost[i][t] = memo[i+1][t]+1; loopcost[i][t] = min(loopcost[i][t], loopcost[i+1][!t]+!t); } else { for (int j = i; j < n; j++) { if ((b[j] == b[i]) != isok) { isok = !isok; istoggled = !istoggled; if (istoggled) extracost++; } int am = memo[j+1][istoggled]+extracost; loopcost[i][t] = min(loopcost[i][t], am); } } ans = min(ans, loopcost[i][t]); memo[i][t] = ans; } } int ans = memo[0][0]; printf("%d\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 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 | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 512 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 | 3 ms | 384 KB | Output is correct |
22 | Correct | 3 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 3 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 3 ms | 384 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 | 3 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 3 ms | 384 KB | Output is correct |
34 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 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 | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 512 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 | 3 ms | 384 KB | Output is correct |
22 | Correct | 3 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 3 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 3 ms | 384 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 | 3 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 3 ms | 384 KB | Output is correct |
34 | Correct | 3 ms | 384 KB | Output is correct |
35 | Correct | 3 ms | 384 KB | Output is correct |
36 | Correct | 2 ms | 384 KB | Output is correct |
37 | Correct | 2 ms | 384 KB | Output is correct |
38 | Correct | 2 ms | 384 KB | Output is correct |
39 | Correct | 3 ms | 384 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 2 ms | 384 KB | Output is correct |
42 | Correct | 2 ms | 384 KB | Output is correct |
43 | Correct | 3 ms | 384 KB | Output is correct |
44 | Correct | 2 ms | 384 KB | Output is correct |
45 | Correct | 3 ms | 384 KB | Output is correct |
46 | Correct | 3 ms | 384 KB | Output is correct |
47 | Correct | 2 ms | 384 KB | Output is correct |
48 | Correct | 2 ms | 384 KB | Output is correct |
49 | Correct | 2 ms | 384 KB | Output is correct |
50 | Correct | 2 ms | 384 KB | Output is correct |
51 | Correct | 3 ms | 384 KB | Output is correct |
52 | Correct | 3 ms | 384 KB | Output is correct |
53 | Correct | 2 ms | 384 KB | Output is correct |
54 | Correct | 2 ms | 384 KB | Output is correct |
55 | Correct | 2 ms | 384 KB | Output is correct |
56 | Correct | 3 ms | 384 KB | Output is correct |
57 | Correct | 3 ms | 384 KB | Output is correct |
58 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 139 ms | 23800 KB | Output is correct |
8 | Correct | 131 ms | 23928 KB | Output is correct |
9 | Correct | 118 ms | 25720 KB | Output is correct |
10 | Correct | 144 ms | 25720 KB | Output is correct |
11 | Correct | 126 ms | 25720 KB | Output is correct |
12 | Correct | 164 ms | 25712 KB | Output is correct |
13 | Correct | 153 ms | 25752 KB | Output is correct |
14 | Correct | 142 ms | 25852 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 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 | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 512 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 | 3 ms | 384 KB | Output is correct |
22 | Correct | 3 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 3 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 3 ms | 384 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 | 3 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 3 ms | 384 KB | Output is correct |
34 | Correct | 3 ms | 384 KB | Output is correct |
35 | Correct | 3 ms | 384 KB | Output is correct |
36 | Correct | 2 ms | 384 KB | Output is correct |
37 | Correct | 2 ms | 384 KB | Output is correct |
38 | Correct | 2 ms | 384 KB | Output is correct |
39 | Correct | 3 ms | 384 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 2 ms | 384 KB | Output is correct |
42 | Correct | 2 ms | 384 KB | Output is correct |
43 | Correct | 3 ms | 384 KB | Output is correct |
44 | Correct | 2 ms | 384 KB | Output is correct |
45 | Correct | 3 ms | 384 KB | Output is correct |
46 | Correct | 3 ms | 384 KB | Output is correct |
47 | Correct | 2 ms | 384 KB | Output is correct |
48 | Correct | 2 ms | 384 KB | Output is correct |
49 | Correct | 2 ms | 384 KB | Output is correct |
50 | Correct | 2 ms | 384 KB | Output is correct |
51 | Correct | 3 ms | 384 KB | Output is correct |
52 | Correct | 3 ms | 384 KB | Output is correct |
53 | Correct | 2 ms | 384 KB | Output is correct |
54 | Correct | 2 ms | 384 KB | Output is correct |
55 | Correct | 2 ms | 384 KB | Output is correct |
56 | Correct | 3 ms | 384 KB | Output is correct |
57 | Correct | 3 ms | 384 KB | Output is correct |
58 | Correct | 2 ms | 384 KB | Output is correct |
59 | Correct | 2 ms | 384 KB | Output is correct |
60 | Correct | 2 ms | 384 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 | 139 ms | 23800 KB | Output is correct |
66 | Correct | 131 ms | 23928 KB | Output is correct |
67 | Correct | 118 ms | 25720 KB | Output is correct |
68 | Correct | 144 ms | 25720 KB | Output is correct |
69 | Correct | 126 ms | 25720 KB | Output is correct |
70 | Correct | 164 ms | 25712 KB | Output is correct |
71 | Correct | 153 ms | 25752 KB | Output is correct |
72 | Correct | 142 ms | 25852 KB | Output is correct |
73 | Correct | 116 ms | 25696 KB | Output is correct |
74 | Correct | 119 ms | 25848 KB | Output is correct |
75 | Correct | 129 ms | 25720 KB | Output is correct |
76 | Correct | 165 ms | 25772 KB | Output is correct |
77 | Correct | 148 ms | 25720 KB | Output is correct |
78 | Correct | 145 ms | 25720 KB | Output is correct |
79 | Correct | 142 ms | 25848 KB | Output is correct |
80 | Correct | 131 ms | 25720 KB | Output is correct |
81 | Correct | 123 ms | 25868 KB | Output is correct |
82 | Correct | 141 ms | 25692 KB | Output is correct |
83 | Correct | 162 ms | 25812 KB | Output is correct |
84 | Correct | 152 ms | 25848 KB | Output is correct |
85 | Correct | 146 ms | 25836 KB | Output is correct |
86 | Correct | 148 ms | 25852 KB | Output is correct |
87 | Correct | 138 ms | 25948 KB | Output is correct |
88 | Correct | 140 ms | 25760 KB | Output is correct |
89 | Correct | 226 ms | 25720 KB | Output is correct |
90 | Correct | 167 ms | 25848 KB | Output is correct |
91 | Correct | 167 ms | 25852 KB | Output is correct |
92 | Correct | 149 ms | 25720 KB | Output is correct |
93 | Correct | 172 ms | 25800 KB | Output is correct |
94 | Correct | 146 ms | 25868 KB | Output is correct |
95 | Correct | 157 ms | 25852 KB | Output is correct |
96 | Correct | 139 ms | 25720 KB | Output is correct |
97 | Correct | 144 ms | 25720 KB | Output is correct |
98 | Correct | 147 ms | 25776 KB | Output is correct |
99 | Correct | 170 ms | 25796 KB | Output is correct |
100 | Correct | 151 ms | 25948 KB | Output is correct |
101 | Correct | 155 ms | 25848 KB | Output is correct |
102 | Correct | 160 ms | 25908 KB | Output is correct |