# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97386 | 2019-02-15T16:59:16 Z | Bruteforceman | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++11 | 378 ms | 194412 KB |
#include "bits/stdc++.h" using namespace std; int a[444]; int n; const int inf = 1e9; int dp[3][405][405][405]; bool vis[405]; int cnt[3][404]; vector <int> col[3]; int main(int argc, char const *argv[]) { // memset(mem, -1, sizeof mem); scanf("%d", &n); char txt[444]; scanf("%s", txt); for(int i = 0; i < n; i++) { if(txt[i] == 'R') { a[i+1] = 0; } else if (txt[i] == 'G') { a[i+1] = 1; } else { a[i+1] = 2; } } col[0].push_back(0); col[1].push_back(0); col[2].push_back(0); for(int i = 1; i <= n; i++) { for(int k = 0; k < 3; k++) { cnt[k][i] = cnt[k][i - 1]; } cnt[a[i]][i] += 1; col[a[i]].push_back(i); } int R = col[0].size() - 1; int B = col[1].size() - 1; int G = col[2].size() - 1; for(int last = 0; last < 3; last++) { for(int r = 0; r <= R; r++) { for(int b = 0; b <= B; b++) { for(int g = 0; g <= G; g++) { dp[last][r][b][g] = inf; } } } } dp[0][0][0][0] = 0; dp[1][0][0][0] = 0; dp[2][0][0][0] = 0; for(int r = 0; r <= R; r++) { for(int b = 0; b <= B; b++) { for(int g = 0; g <= G; g++) { for(int last = 0; last < 3; last++) { int ans = dp[last][r][b][g]; int c[3]; c[0] = r; c[1] = b; c[2] = g; for(int i = 0; i < 3; i++) { if(col[i].size() <= c[i] + 1 || last == i) continue; int pos = col[i][c[i] + 1]; int tot = -1; for(int x = 0; x < 3; x++) { int prev = col[x][c[x]]; tot += max(0, cnt[x][pos] - cnt[x][prev]); } c[i] += 1; dp[i][c[0]][c[1]][c[2]] = min(dp[i][c[0]][c[1]][c[2]], tot + ans); c[i] -= 1; } } } } } int ans = inf; for(int i = 0; i < 3; i++) { ans = min(ans, dp[i][R][B][G]); } printf("%d\n", ans >= inf ? -1 : ans); return 0; }
Compilation message
# | 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 | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 640 KB | Output is correct |
9 | Correct | 2 ms | 768 KB | Output is correct |
10 | Correct | 2 ms | 768 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 512 KB | Output is correct |
14 | Correct | 3 ms | 640 KB | Output is correct |
15 | Correct | 3 ms | 512 KB | Output is correct |
16 | Correct | 3 ms | 512 KB | Output is correct |
17 | Correct | 3 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 | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 640 KB | Output is correct |
9 | Correct | 2 ms | 768 KB | Output is correct |
10 | Correct | 2 ms | 768 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 512 KB | Output is correct |
14 | Correct | 3 ms | 640 KB | Output is correct |
15 | Correct | 3 ms | 512 KB | Output is correct |
16 | Correct | 3 ms | 512 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 2688 KB | Output is correct |
19 | Correct | 6 ms | 2304 KB | Output is correct |
20 | Correct | 4 ms | 2688 KB | Output is correct |
21 | Correct | 7 ms | 2816 KB | Output is correct |
22 | Correct | 2 ms | 2048 KB | Output is correct |
23 | Correct | 4 ms | 2432 KB | Output is correct |
24 | Correct | 5 ms | 1948 KB | Output is correct |
25 | Correct | 7 ms | 4864 KB | Output is correct |
26 | Correct | 6 ms | 5120 KB | Output is correct |
27 | Correct | 5 ms | 3712 KB | Output is correct |
28 | Correct | 6 ms | 2816 KB | Output is correct |
29 | Correct | 5 ms | 2688 KB | Output is correct |
30 | Correct | 4 ms | 2688 KB | Output is correct |
31 | Correct | 4 ms | 2304 KB | Output is correct |
32 | Correct | 5 ms | 2816 KB | Output is correct |
33 | Correct | 6 ms | 4736 KB | Output is correct |
34 | Correct | 6 ms | 4224 KB | Output is correct |
35 | Correct | 5 ms | 3200 KB | Output is correct |
36 | Correct | 5 ms | 2304 KB | Output is correct |
37 | Correct | 4 ms | 1920 KB | Output is correct |
38 | Correct | 5 ms | 2560 KB | Output is correct |
39 | Correct | 5 ms | 2816 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 1 ms | 2560 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 169 ms | 194296 KB | Output is correct |
3 | Correct | 160 ms | 193400 KB | Output is correct |
4 | Correct | 168 ms | 194412 KB | Output is correct |
5 | Correct | 156 ms | 194296 KB | Output is correct |
6 | Correct | 153 ms | 194308 KB | Output is correct |
7 | Correct | 154 ms | 193440 KB | Output is correct |
8 | Correct | 156 ms | 193484 KB | Output is correct |
9 | Correct | 148 ms | 192476 KB | Output is correct |
10 | Correct | 143 ms | 194260 KB | Output is correct |
11 | Correct | 157 ms | 194244 KB | Output is correct |
12 | Correct | 41 ms | 52856 KB | Output is correct |
13 | Correct | 70 ms | 92280 KB | Output is correct |
14 | Correct | 108 ms | 132984 KB | Output is correct |
15 | Correct | 171 ms | 194316 KB | Output is correct |
16 | Correct | 168 ms | 194296 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 | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 640 KB | Output is correct |
9 | Correct | 2 ms | 768 KB | Output is correct |
10 | Correct | 2 ms | 768 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 512 KB | Output is correct |
14 | Correct | 3 ms | 640 KB | Output is correct |
15 | Correct | 3 ms | 512 KB | Output is correct |
16 | Correct | 3 ms | 512 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 2688 KB | Output is correct |
19 | Correct | 6 ms | 2304 KB | Output is correct |
20 | Correct | 4 ms | 2688 KB | Output is correct |
21 | Correct | 7 ms | 2816 KB | Output is correct |
22 | Correct | 2 ms | 2048 KB | Output is correct |
23 | Correct | 4 ms | 2432 KB | Output is correct |
24 | Correct | 5 ms | 1948 KB | Output is correct |
25 | Correct | 7 ms | 4864 KB | Output is correct |
26 | Correct | 6 ms | 5120 KB | Output is correct |
27 | Correct | 5 ms | 3712 KB | Output is correct |
28 | Correct | 6 ms | 2816 KB | Output is correct |
29 | Correct | 5 ms | 2688 KB | Output is correct |
30 | Correct | 4 ms | 2688 KB | Output is correct |
31 | Correct | 4 ms | 2304 KB | Output is correct |
32 | Correct | 5 ms | 2816 KB | Output is correct |
33 | Correct | 6 ms | 4736 KB | Output is correct |
34 | Correct | 6 ms | 4224 KB | Output is correct |
35 | Correct | 5 ms | 3200 KB | Output is correct |
36 | Correct | 5 ms | 2304 KB | Output is correct |
37 | Correct | 4 ms | 1920 KB | Output is correct |
38 | Correct | 5 ms | 2560 KB | Output is correct |
39 | Correct | 5 ms | 2816 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 1 ms | 2560 KB | Output is correct |
42 | Correct | 3 ms | 384 KB | Output is correct |
43 | Correct | 169 ms | 194296 KB | Output is correct |
44 | Correct | 160 ms | 193400 KB | Output is correct |
45 | Correct | 168 ms | 194412 KB | Output is correct |
46 | Correct | 156 ms | 194296 KB | Output is correct |
47 | Correct | 153 ms | 194308 KB | Output is correct |
48 | Correct | 154 ms | 193440 KB | Output is correct |
49 | Correct | 156 ms | 193484 KB | Output is correct |
50 | Correct | 148 ms | 192476 KB | Output is correct |
51 | Correct | 143 ms | 194260 KB | Output is correct |
52 | Correct | 157 ms | 194244 KB | Output is correct |
53 | Correct | 41 ms | 52856 KB | Output is correct |
54 | Correct | 70 ms | 92280 KB | Output is correct |
55 | Correct | 108 ms | 132984 KB | Output is correct |
56 | Correct | 171 ms | 194316 KB | Output is correct |
57 | Correct | 168 ms | 194296 KB | Output is correct |
58 | Correct | 316 ms | 77364 KB | Output is correct |
59 | Correct | 291 ms | 97740 KB | Output is correct |
60 | Correct | 267 ms | 88952 KB | Output is correct |
61 | Correct | 324 ms | 86136 KB | Output is correct |
62 | Correct | 171 ms | 189432 KB | Output is correct |
63 | Correct | 178 ms | 186640 KB | Output is correct |
64 | Correct | 288 ms | 163064 KB | Output is correct |
65 | Correct | 336 ms | 142072 KB | Output is correct |
66 | Correct | 300 ms | 87532 KB | Output is correct |
67 | Correct | 314 ms | 83964 KB | Output is correct |
68 | Correct | 378 ms | 89848 KB | Output is correct |
69 | Correct | 375 ms | 86648 KB | Output is correct |
70 | Correct | 338 ms | 93688 KB | Output is correct |
71 | Correct | 325 ms | 85376 KB | Output is correct |
72 | Correct | 103 ms | 44024 KB | Output is correct |
73 | Correct | 21 ms | 2944 KB | Output is correct |