# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
373181 | 2021-03-03T15:56:05 Z | luciocf | Lamps (JOI19_lamps) | C++14 | 73 ms | 23276 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3+10; char a[maxn], b[maxn]; int comp[maxn][maxn][2]; int dp[maxn][2]; int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf(" %c", &a[i]); for (int i = 1; i <= n; i++) scanf(" %c", &b[i]); for (int l = 1; l <= n; l++) { comp[l][l][0] = (b[l] == '0' ? 0 : 1); for (int r = l+1; r <= n; r++) { if (b[r] == '0' || b[r-1] == '1') comp[l][r][0] = comp[l][r-1][0]; else comp[l][r][0] = comp[l][r-1][0]+1; } comp[l][l][1] = (b[l] == '1' ? 0 : 1); for (int r = l+1; r <= n; r++) { if (b[r] == '1' || b[r-1] == '0') comp[l][r][1] = comp[l][r-1][1]; else comp[l][r][1] = comp[l][r-1][1]+1; } } for (int i = 1; i <= n; i++) { dp[i][0] = dp[i][1] = n+1; int um = 0; for (int j = i-1; j >= 0; j--) { um |= (a[j+1] == '1'); int add = (j > 0 && b[j] == '0' && b[j+1] == '1'); dp[i][0] = min(dp[i][0], um + comp[j+1][i][0] - add + dp[j][1]); } int zero = 0; for (int j = i-1; j >= 0; j--) { zero |= (a[j+1] == '0'); int add = (j > 0 && b[j] == '1' && b[j+1] == '0'); dp[i][1] = min(dp[i][1], zero + comp[j+1][i][1] - add + dp[j][0]); } } printf("%d\n", min(dp[n][0], dp[n][1])); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 364 KB | Output is correct |
16 | Correct | 1 ms | 492 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 | 364 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 | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 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 | 364 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 | 364 KB | Output is correct |
16 | Correct | 1 ms | 492 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 | 364 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 | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 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 | 364 KB | Output is correct |
34 | Correct | 1 ms | 364 KB | Output is correct |
35 | Correct | 51 ms | 23020 KB | Output is correct |
36 | Correct | 50 ms | 23020 KB | Output is correct |
37 | Correct | 51 ms | 23020 KB | Output is correct |
38 | Correct | 53 ms | 23020 KB | Output is correct |
39 | Correct | 56 ms | 23148 KB | Output is correct |
40 | Correct | 72 ms | 23020 KB | Output is correct |
41 | Correct | 62 ms | 23020 KB | Output is correct |
42 | Correct | 55 ms | 23020 KB | Output is correct |
43 | Correct | 60 ms | 23148 KB | Output is correct |
44 | Correct | 57 ms | 23020 KB | Output is correct |
45 | Correct | 58 ms | 23148 KB | Output is correct |
46 | Correct | 57 ms | 23020 KB | Output is correct |
47 | Correct | 60 ms | 23020 KB | Output is correct |
48 | Correct | 58 ms | 23020 KB | Output is correct |
49 | Correct | 73 ms | 23020 KB | Output is correct |
50 | Correct | 58 ms | 23020 KB | Output is correct |
51 | Correct | 58 ms | 23276 KB | Output is correct |
52 | Correct | 61 ms | 23148 KB | Output is correct |
53 | Correct | 72 ms | 23032 KB | Output is correct |
54 | Correct | 71 ms | 23148 KB | Output is correct |
55 | Correct | 60 ms | 23020 KB | Output is correct |
56 | Correct | 57 ms | 23020 KB | Output is correct |
57 | Correct | 57 ms | 23020 KB | Output is correct |
58 | Correct | 59 ms | 23020 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 | Execution timed out | 2 ms | 364 KB | Time limit exceeded (wall clock) |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | 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 | 364 KB | Output is correct |
16 | Correct | 1 ms | 492 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 | 364 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 | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 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 | 364 KB | Output is correct |
34 | Correct | 1 ms | 364 KB | Output is correct |
35 | Correct | 51 ms | 23020 KB | Output is correct |
36 | Correct | 50 ms | 23020 KB | Output is correct |
37 | Correct | 51 ms | 23020 KB | Output is correct |
38 | Correct | 53 ms | 23020 KB | Output is correct |
39 | Correct | 56 ms | 23148 KB | Output is correct |
40 | Correct | 72 ms | 23020 KB | Output is correct |
41 | Correct | 62 ms | 23020 KB | Output is correct |
42 | Correct | 55 ms | 23020 KB | Output is correct |
43 | Correct | 60 ms | 23148 KB | Output is correct |
44 | Correct | 57 ms | 23020 KB | Output is correct |
45 | Correct | 58 ms | 23148 KB | Output is correct |
46 | Correct | 57 ms | 23020 KB | Output is correct |
47 | Correct | 60 ms | 23020 KB | Output is correct |
48 | Correct | 58 ms | 23020 KB | Output is correct |
49 | Correct | 73 ms | 23020 KB | Output is correct |
50 | Correct | 58 ms | 23020 KB | Output is correct |
51 | Correct | 58 ms | 23276 KB | Output is correct |
52 | Correct | 61 ms | 23148 KB | Output is correct |
53 | Correct | 72 ms | 23032 KB | Output is correct |
54 | Correct | 71 ms | 23148 KB | Output is correct |
55 | Correct | 60 ms | 23020 KB | Output is correct |
56 | Correct | 57 ms | 23020 KB | Output is correct |
57 | Correct | 57 ms | 23020 KB | Output is correct |
58 | Correct | 59 ms | 23020 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 | Execution timed out | 2 ms | 364 KB | Time limit exceeded (wall clock) |
66 | Halted | 0 ms | 0 KB | - |