# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
99027 | 2019-02-28T06:13:13 Z | kriii | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 427 ms | 57336 KB |
#include <stdio.h> #include <algorithm> #include <vector> using namespace std; vector<int> pos[3]; int N; char S[404]; int T[404]; int X,C[3000000][3],D[3000000][3]; int tr(int i, int j, int k) { return (i * (pos[1].size() + 1) + j) * (pos[2].size() + 1) + k; } int main() { scanf ("%d",&N); scanf ("%s",S); for (int i=0;i<N;i++){ if (S[i] == 'R') T[i] = 0; if (S[i] == 'G') T[i] = 1; if (S[i] == 'Y') T[i] = 2; pos[T[i]].push_back(i); } for (int i=0;i<=pos[0].size();i++) for (int j=0;j<=pos[1].size();j++) for (int k=0;k<=pos[2].size();k++){ C[X][0] = i; C[X][1] = j; C[X][2] = k; D[X][0] = D[X][1] = D[X][2] = 0x7fffff; X++; } D[0][0] = D[0][1] = D[0][2] = 0; for (int x=0;x<X;x++){ int c[3] = {C[x][0], C[x][1], C[x][2]}; for (int k=0;k<3;k++) if (c[k] < pos[k].size()){ int v = 0, u = pos[k][c[k]]; for (int l=0;l<3;l++) if (l != k) v += pos[l].begin()+c[l] - upper_bound(pos[l].begin(),pos[l].begin()+c[l],u); c[k]++; int t = tr(c[0],c[1],c[2]); for (int l=0;l<3;l++) if (l != k){ if (D[x][l] == 0x7fffff) continue; int d = D[x][l] + v; if (D[t][k] > d) D[t][k] = d; } c[k]--; } } int ans = min({D[X-1][0],D[X-1][1],D[X-1][2]}); if (ans == 0x7fffff) ans = -1; printf ("%d\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 284 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 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 | 384 KB | Output is correct |
17 | Correct | 3 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 284 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 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 | 384 KB | Output is correct |
17 | Correct | 3 ms | 256 KB | Output is correct |
18 | Correct | 4 ms | 512 KB | Output is correct |
19 | Correct | 3 ms | 512 KB | Output is correct |
20 | Correct | 3 ms | 512 KB | Output is correct |
21 | Correct | 4 ms | 512 KB | Output is correct |
22 | Correct | 3 ms | 512 KB | Output is correct |
23 | Correct | 3 ms | 512 KB | Output is correct |
24 | Correct | 3 ms | 512 KB | Output is correct |
25 | Correct | 3 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 4 ms | 512 KB | Output is correct |
28 | Correct | 1 ms | 512 KB | Output is correct |
29 | Correct | 4 ms | 512 KB | Output is correct |
30 | Correct | 3 ms | 512 KB | Output is correct |
31 | Correct | 3 ms | 560 KB | Output is correct |
32 | Correct | 0 ms | 512 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 3 ms | 384 KB | Output is correct |
35 | Correct | 3 ms | 512 KB | Output is correct |
36 | Correct | 3 ms | 512 KB | Output is correct |
37 | Correct | 3 ms | 512 KB | Output is correct |
38 | Correct | 4 ms | 484 KB | Output is correct |
39 | Correct | 4 ms | 512 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 1280 KB | Output is correct |
3 | Correct | 5 ms | 1408 KB | Output is correct |
4 | Correct | 6 ms | 1280 KB | Output is correct |
5 | Correct | 6 ms | 1280 KB | Output is correct |
6 | Correct | 5 ms | 1280 KB | Output is correct |
7 | Correct | 5 ms | 1280 KB | Output is correct |
8 | Correct | 6 ms | 1280 KB | Output is correct |
9 | Correct | 6 ms | 1280 KB | Output is correct |
10 | Correct | 6 ms | 1280 KB | Output is correct |
11 | Correct | 6 ms | 1288 KB | Output is correct |
12 | Correct | 3 ms | 512 KB | Output is correct |
13 | Correct | 5 ms | 768 KB | Output is correct |
14 | Correct | 4 ms | 1024 KB | Output is correct |
15 | Correct | 5 ms | 1280 KB | Output is correct |
16 | Correct | 6 ms | 1280 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 284 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 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 | 384 KB | Output is correct |
17 | Correct | 3 ms | 256 KB | Output is correct |
18 | Correct | 4 ms | 512 KB | Output is correct |
19 | Correct | 3 ms | 512 KB | Output is correct |
20 | Correct | 3 ms | 512 KB | Output is correct |
21 | Correct | 4 ms | 512 KB | Output is correct |
22 | Correct | 3 ms | 512 KB | Output is correct |
23 | Correct | 3 ms | 512 KB | Output is correct |
24 | Correct | 3 ms | 512 KB | Output is correct |
25 | Correct | 3 ms | 384 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 4 ms | 512 KB | Output is correct |
28 | Correct | 1 ms | 512 KB | Output is correct |
29 | Correct | 4 ms | 512 KB | Output is correct |
30 | Correct | 3 ms | 512 KB | Output is correct |
31 | Correct | 3 ms | 560 KB | Output is correct |
32 | Correct | 0 ms | 512 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 3 ms | 384 KB | Output is correct |
35 | Correct | 3 ms | 512 KB | Output is correct |
36 | Correct | 3 ms | 512 KB | Output is correct |
37 | Correct | 3 ms | 512 KB | Output is correct |
38 | Correct | 4 ms | 484 KB | Output is correct |
39 | Correct | 4 ms | 512 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 | 256 KB | Output is correct |
43 | Correct | 5 ms | 1280 KB | Output is correct |
44 | Correct | 5 ms | 1408 KB | Output is correct |
45 | Correct | 6 ms | 1280 KB | Output is correct |
46 | Correct | 6 ms | 1280 KB | Output is correct |
47 | Correct | 5 ms | 1280 KB | Output is correct |
48 | Correct | 5 ms | 1280 KB | Output is correct |
49 | Correct | 6 ms | 1280 KB | Output is correct |
50 | Correct | 6 ms | 1280 KB | Output is correct |
51 | Correct | 6 ms | 1280 KB | Output is correct |
52 | Correct | 6 ms | 1288 KB | Output is correct |
53 | Correct | 3 ms | 512 KB | Output is correct |
54 | Correct | 5 ms | 768 KB | Output is correct |
55 | Correct | 4 ms | 1024 KB | Output is correct |
56 | Correct | 5 ms | 1280 KB | Output is correct |
57 | Correct | 6 ms | 1280 KB | Output is correct |
58 | Correct | 358 ms | 56648 KB | Output is correct |
59 | Correct | 381 ms | 56696 KB | Output is correct |
60 | Correct | 427 ms | 56184 KB | Output is correct |
61 | Correct | 403 ms | 57004 KB | Output is correct |
62 | Correct | 24 ms | 4964 KB | Output is correct |
63 | Correct | 58 ms | 8576 KB | Output is correct |
64 | Correct | 146 ms | 28280 KB | Output is correct |
65 | Correct | 271 ms | 40468 KB | Output is correct |
66 | Correct | 269 ms | 55996 KB | Output is correct |
67 | Correct | 300 ms | 56032 KB | Output is correct |
68 | Correct | 300 ms | 56952 KB | Output is correct |
69 | Correct | 327 ms | 57336 KB | Output is correct |
70 | Correct | 344 ms | 57084 KB | Output is correct |
71 | Correct | 350 ms | 55760 KB | Output is correct |
72 | Correct | 102 ms | 14592 KB | Output is correct |
73 | Correct | 29 ms | 3968 KB | Output is correct |