Submission #97401

# Submission time Handle Problem Language Result Execution time Memory
97401 2019-02-15T17:43:48 Z kdh9949 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
283 ms 165112 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 405, INF = int(1e9);

int n, tt[3], s[6][N], p[3][N], d[N][N][N][3];
char b[N];

int main(){
    scanf("%d%s", &n, b + 1);
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 6; j++) s[j][i] = s[j][i - 1];
        int t = (b[i] == 'R' ? 0 : b[i] == 'G' ? 1 : 2);
        s[t][i]++;
        s[t + 3][i]++;
        p[t][tt[t]++] = i;
    }
    for(int r = tt[0] + 1; r >= 0; r--){
        for(int g = tt[1] + 1; g >= 0; g--){
            for(int y = tt[2] + 1; y >= 0; y--){
                for(int l = 0; l < 3; l++){
                    int &ret = d[r][g][y][l];
                    if(r > tt[0] || g > tt[1] || y > tt[2]){ ret = INF; continue; }
                    if(r + g + y == n){ ret = 0; continue; }
                    ret = INF;
                    int a[5] = {r, g, y, r, g};
                    for(int i = 0; i < 3; i++){
                        if(i == l) continue;
                        ret = min(ret,
                                d[r + (i == 0)][g + (i == 1)][y + (i == 2)][i]
                                + max(0, s[i + 1][p[i][a[i]]] - a[i + 1])
                                + max(0, s[i + 2][p[i][a[i]]] - a[i + 2]));
                    }
                }
            }
        }
    }
    int r = min({d[1][0][0][0] + p[0][0] - 1,
                 d[0][1][0][1] + p[1][0] - 1,
                 d[0][0][1][2] + p[2][0] - 1});
    if(r > INF / 2) puts("-1");
    else printf("%d\n", r);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%s", &n, b + 1);
     ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 512 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 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 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory 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 512 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 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 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 6 ms 2560 KB Output is correct
19 Correct 4 ms 2048 KB Output is correct
20 Correct 7 ms 2560 KB Output is correct
21 Correct 5 ms 2560 KB Output is correct
22 Correct 3 ms 1920 KB Output is correct
23 Correct 4 ms 2304 KB Output is correct
24 Correct 4 ms 1792 KB Output is correct
25 Correct 5 ms 4224 KB Output is correct
26 Correct 6 ms 4480 KB Output is correct
27 Correct 5 ms 3328 KB Output is correct
28 Correct 4 ms 2560 KB Output is correct
29 Correct 5 ms 2432 KB Output is correct
30 Correct 5 ms 2560 KB Output is correct
31 Correct 4 ms 2148 KB Output is correct
32 Correct 5 ms 2532 KB Output is correct
33 Correct 7 ms 4096 KB Output is correct
34 Correct 5 ms 3840 KB Output is correct
35 Correct 5 ms 3072 KB Output is correct
36 Correct 4 ms 2176 KB Output is correct
37 Correct 3 ms 1920 KB Output is correct
38 Correct 4 ms 2304 KB Output is correct
39 Correct 4 ms 2560 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 5 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 149 ms 165060 KB Output is correct
3 Correct 142 ms 164252 KB Output is correct
4 Correct 133 ms 165112 KB Output is correct
5 Correct 129 ms 165084 KB Output is correct
6 Correct 111 ms 165036 KB Output is correct
7 Correct 109 ms 164216 KB Output is correct
8 Correct 120 ms 164268 KB Output is correct
9 Correct 130 ms 163524 KB Output is correct
10 Correct 139 ms 165024 KB Output is correct
11 Correct 118 ms 165112 KB Output is correct
12 Correct 36 ms 45020 KB Output is correct
13 Correct 60 ms 78456 KB Output is correct
14 Correct 88 ms 113144 KB Output is correct
15 Correct 130 ms 165112 KB Output is correct
16 Correct 130 ms 165112 KB Output is correct
# Verdict Execution time Memory 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 512 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 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 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 6 ms 2560 KB Output is correct
19 Correct 4 ms 2048 KB Output is correct
20 Correct 7 ms 2560 KB Output is correct
21 Correct 5 ms 2560 KB Output is correct
22 Correct 3 ms 1920 KB Output is correct
23 Correct 4 ms 2304 KB Output is correct
24 Correct 4 ms 1792 KB Output is correct
25 Correct 5 ms 4224 KB Output is correct
26 Correct 6 ms 4480 KB Output is correct
27 Correct 5 ms 3328 KB Output is correct
28 Correct 4 ms 2560 KB Output is correct
29 Correct 5 ms 2432 KB Output is correct
30 Correct 5 ms 2560 KB Output is correct
31 Correct 4 ms 2148 KB Output is correct
32 Correct 5 ms 2532 KB Output is correct
33 Correct 7 ms 4096 KB Output is correct
34 Correct 5 ms 3840 KB Output is correct
35 Correct 5 ms 3072 KB Output is correct
36 Correct 4 ms 2176 KB Output is correct
37 Correct 3 ms 1920 KB Output is correct
38 Correct 4 ms 2304 KB Output is correct
39 Correct 4 ms 2560 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 5 ms 2560 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 149 ms 165060 KB Output is correct
44 Correct 142 ms 164252 KB Output is correct
45 Correct 133 ms 165112 KB Output is correct
46 Correct 129 ms 165084 KB Output is correct
47 Correct 111 ms 165036 KB Output is correct
48 Correct 109 ms 164216 KB Output is correct
49 Correct 120 ms 164268 KB Output is correct
50 Correct 130 ms 163524 KB Output is correct
51 Correct 139 ms 165024 KB Output is correct
52 Correct 118 ms 165112 KB Output is correct
53 Correct 36 ms 45020 KB Output is correct
54 Correct 60 ms 78456 KB Output is correct
55 Correct 88 ms 113144 KB Output is correct
56 Correct 130 ms 165112 KB Output is correct
57 Correct 130 ms 165112 KB Output is correct
58 Correct 221 ms 77516 KB Output is correct
59 Correct 252 ms 98040 KB Output is correct
60 Correct 214 ms 89208 KB Output is correct
61 Correct 276 ms 86276 KB Output is correct
62 Correct 169 ms 162680 KB Output is correct
63 Correct 142 ms 162424 KB Output is correct
64 Correct 213 ms 152244 KB Output is correct
65 Correct 218 ms 140492 KB Output is correct
66 Correct 218 ms 87416 KB Output is correct
67 Correct 203 ms 84344 KB Output is correct
68 Correct 283 ms 89976 KB Output is correct
69 Correct 173 ms 86648 KB Output is correct
70 Correct 246 ms 93948 KB Output is correct
71 Correct 213 ms 85264 KB Output is correct
72 Correct 77 ms 43256 KB Output is correct
73 Correct 19 ms 3584 KB Output is correct