# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
121060 | 2019-06-26T04:26:51 Z | 김현수(#3331) | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 221 ms | 163064 KB |
#include<bits/stdc++.h> using namespace std; const int N = 405, inf = 1e9; const char TYP[5] = "RGY"; int n, dt[N][N][N][3], s[N][3], z[3], idx[3][N]; char a[N]; int main() { scanf("%d%s",&n,a+1); for(int i=1;i<=n;i++) { for(int j=0;j<3;j++) { if(a[i] == TYP[j]) { a[i] = j; break; } } idx[a[i]][++z[a[i]]] = i; for(int j=0;j<3;j++) { s[i][j] = s[i-1][j] + (a[i] == j); } } for(int x=1;x<=n;x++) { int c[3]; for(c[0]=0;c[0]<=z[0];c[0]++) { for(c[1]=0;c[1]<=z[1];c[1]++) { c[2] = x - c[0] - c[1]; if(c[2] > z[2] || c[2] < 0) continue; for(int i=0;i<3;i++) { if(c[i] == 0) { dt[c[0]][c[1]][c[2]][i] = inf; continue; } int X = idx[i][c[i]], T = inf; for(int j=0;j<3;j++) { X -= min(c[j], s[idx[i][c[i]]][j]); } c[i]--; T = min(T, min(dt[c[0]][c[1]][c[2]][(i+1)%3], dt[c[0]][c[1]][c[2]][(i+2)%3]) + X); c[i]++; dt[c[0]][c[1]][c[2]][i] = T; } } } } int ans = min({dt[z[0]][z[1]][z[2]][0], dt[z[0]][z[1]][z[2]][1], dt[z[0]][z[1]][z[2]][2]}); printf("%d\n", ans == inf ? -1 : ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 512 KB | Output is correct |
7 | Correct | 2 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 3 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 640 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 2 ms | 512 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 512 KB | Output is correct |
15 | Correct | 2 ms | 512 KB | Output is correct |
16 | Correct | 2 ms | 512 KB | Output is correct |
17 | 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 | 512 KB | Output is correct |
7 | Correct | 2 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 3 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 640 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 2 ms | 512 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 512 KB | Output is correct |
15 | Correct | 2 ms | 512 KB | Output is correct |
16 | Correct | 2 ms | 512 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 3 ms | 2304 KB | Output is correct |
19 | Correct | 3 ms | 2176 KB | Output is correct |
20 | Correct | 4 ms | 2304 KB | Output is correct |
21 | Correct | 3 ms | 2432 KB | Output is correct |
22 | Correct | 3 ms | 1664 KB | Output is correct |
23 | Correct | 4 ms | 2220 KB | Output is correct |
24 | Correct | 3 ms | 1664 KB | Output is correct |
25 | Correct | 4 ms | 3968 KB | Output is correct |
26 | Correct | 5 ms | 4224 KB | Output is correct |
27 | Correct | 5 ms | 3072 KB | Output is correct |
28 | Correct | 4 ms | 2304 KB | Output is correct |
29 | Correct | 4 ms | 2304 KB | Output is correct |
30 | Correct | 4 ms | 2304 KB | Output is correct |
31 | Correct | 3 ms | 2048 KB | Output is correct |
32 | Correct | 4 ms | 2432 KB | Output is correct |
33 | Correct | 5 ms | 3968 KB | Output is correct |
34 | Correct | 6 ms | 3584 KB | Output is correct |
35 | Correct | 4 ms | 2660 KB | Output is correct |
36 | Correct | 3 ms | 1920 KB | Output is correct |
37 | Correct | 4 ms | 1792 KB | Output is correct |
38 | Correct | 4 ms | 2176 KB | Output is correct |
39 | Correct | 4 ms | 2432 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 3 ms | 2304 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 155 ms | 162936 KB | Output is correct |
3 | Correct | 154 ms | 162296 KB | Output is correct |
4 | Correct | 156 ms | 162936 KB | Output is correct |
5 | Correct | 154 ms | 162936 KB | Output is correct |
6 | Correct | 221 ms | 163064 KB | Output is correct |
7 | Correct | 151 ms | 162172 KB | Output is correct |
8 | Correct | 154 ms | 162168 KB | Output is correct |
9 | Correct | 147 ms | 161392 KB | Output is correct |
10 | Correct | 149 ms | 162996 KB | Output is correct |
11 | Correct | 152 ms | 163064 KB | Output is correct |
12 | Correct | 38 ms | 44024 KB | Output is correct |
13 | Correct | 67 ms | 77176 KB | Output is correct |
14 | Correct | 97 ms | 111480 KB | Output is correct |
15 | Correct | 145 ms | 162936 KB | Output is correct |
16 | Correct | 150 ms | 163036 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 | 512 KB | Output is correct |
7 | Correct | 2 ms | 512 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 3 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 640 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 2 ms | 512 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 512 KB | Output is correct |
15 | Correct | 2 ms | 512 KB | Output is correct |
16 | Correct | 2 ms | 512 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 3 ms | 2304 KB | Output is correct |
19 | Correct | 3 ms | 2176 KB | Output is correct |
20 | Correct | 4 ms | 2304 KB | Output is correct |
21 | Correct | 3 ms | 2432 KB | Output is correct |
22 | Correct | 3 ms | 1664 KB | Output is correct |
23 | Correct | 4 ms | 2220 KB | Output is correct |
24 | Correct | 3 ms | 1664 KB | Output is correct |
25 | Correct | 4 ms | 3968 KB | Output is correct |
26 | Correct | 5 ms | 4224 KB | Output is correct |
27 | Correct | 5 ms | 3072 KB | Output is correct |
28 | Correct | 4 ms | 2304 KB | Output is correct |
29 | Correct | 4 ms | 2304 KB | Output is correct |
30 | Correct | 4 ms | 2304 KB | Output is correct |
31 | Correct | 3 ms | 2048 KB | Output is correct |
32 | Correct | 4 ms | 2432 KB | Output is correct |
33 | Correct | 5 ms | 3968 KB | Output is correct |
34 | Correct | 6 ms | 3584 KB | Output is correct |
35 | Correct | 4 ms | 2660 KB | Output is correct |
36 | Correct | 3 ms | 1920 KB | Output is correct |
37 | Correct | 4 ms | 1792 KB | Output is correct |
38 | Correct | 4 ms | 2176 KB | Output is correct |
39 | Correct | 4 ms | 2432 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 3 ms | 2304 KB | Output is correct |
42 | Correct | 2 ms | 384 KB | Output is correct |
43 | Correct | 155 ms | 162936 KB | Output is correct |
44 | Correct | 154 ms | 162296 KB | Output is correct |
45 | Correct | 156 ms | 162936 KB | Output is correct |
46 | Correct | 154 ms | 162936 KB | Output is correct |
47 | Correct | 221 ms | 163064 KB | Output is correct |
48 | Correct | 151 ms | 162172 KB | Output is correct |
49 | Correct | 154 ms | 162168 KB | Output is correct |
50 | Correct | 147 ms | 161392 KB | Output is correct |
51 | Correct | 149 ms | 162996 KB | Output is correct |
52 | Correct | 152 ms | 163064 KB | Output is correct |
53 | Correct | 38 ms | 44024 KB | Output is correct |
54 | Correct | 67 ms | 77176 KB | Output is correct |
55 | Correct | 97 ms | 111480 KB | Output is correct |
56 | Correct | 145 ms | 162936 KB | Output is correct |
57 | Correct | 150 ms | 163036 KB | Output is correct |
58 | Correct | 166 ms | 76288 KB | Output is correct |
59 | Correct | 184 ms | 96560 KB | Output is correct |
60 | Correct | 180 ms | 87896 KB | Output is correct |
61 | Correct | 184 ms | 84940 KB | Output is correct |
62 | Correct | 152 ms | 160760 KB | Output is correct |
63 | Correct | 157 ms | 160248 KB | Output is correct |
64 | Correct | 188 ms | 150264 KB | Output is correct |
65 | Correct | 199 ms | 138616 KB | Output is correct |
66 | Correct | 190 ms | 86168 KB | Output is correct |
67 | Correct | 170 ms | 83036 KB | Output is correct |
68 | Correct | 177 ms | 88716 KB | Output is correct |
69 | Correct | 177 ms | 85624 KB | Output is correct |
70 | Correct | 186 ms | 92664 KB | Output is correct |
71 | Correct | 169 ms | 83960 KB | Output is correct |
72 | Correct | 60 ms | 41588 KB | Output is correct |
73 | Correct | 8 ms | 2944 KB | Output is correct |