Submission #97283

# Submission time Handle Problem Language Result Execution time Memory
97283 2019-02-14T18:26:23 Z model_code Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
127 ms 163128 KB
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 400;
const int INFV = 1001001001;

int N;
char S[MAXN + 1]; int A[MAXN];
int dp[MAXN + 1][MAXN + 1][MAXN + 1][3];
int cnts[3], locs[3][MAXN], prevs[3][MAXN];

void chmin(int& x, int y)
{
    x = min(x, y);
}

int main()
{
    scanf("%d%s", &N, S);

    for (int i = 0; i < N; ++i) {
        switch (S[i]) {
            case 'R': A[i] = 0; break;
            case 'G': A[i] = 1; break;
            case 'Y': A[i] = 2; break;
        }
    }

    for (int i = 0; i < 3; ++i) cnts[i] = 0;
    for (int i = 0; i < N; ++i) {
        locs[A[i]][cnts[A[i]]++] = i;
        for (int j = 0; j < 3; ++j) prevs[j][i] = cnts[j];
    }

    for (int a = 0; a <= cnts[0]; ++a) {
        for (int b = 0; b <= cnts[1]; ++b) {
            for (int c = 0; c <= cnts[2]; ++c) {
                for (int s = 0; s < 3; ++s) {
                    dp[a][b][c][s] = INFV;
                }
            }
        }
    }

    dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;

    for (int a = 0; a <= cnts[0]; ++a) {
        for (int b = 0; b <= cnts[1]; ++b) {
            for (int c = 0; c <= cnts[2]; ++c) {
                for (int s = 0; s < 3; ++s) {
                    if (s != 0 && a < cnts[0]) {
                        int p = locs[0][a];
                        chmin(dp[a + 1][b][c][0], dp[a][b][c][s] + max(0, prevs[1][p] - b) + max(0, prevs[2][p] - c));
                    }
                    if (s != 1 && b < cnts[1]) {
                        int p = locs[1][b];
                        chmin(dp[a][b + 1][c][1], dp[a][b][c][s] + max(0, prevs[0][p] - a) + max(0, prevs[2][p] - c));
                    }
                    if (s != 2 && c < cnts[2]) {
                        int p = locs[2][c];
                        chmin(dp[a][b][c + 1][2], dp[a][b][c][s] + max(0, prevs[0][p] - a) + max(0, prevs[1][p] - b));
                    }
                }
            }
        }
    }

    int ret = min({ dp[cnts[0]][cnts[1]][cnts[2]][0], dp[cnts[0]][cnts[1]][cnts[2]][1], dp[cnts[0]][cnts[1]][cnts[2]][2] });
    if (ret >= INFV) ret = -1;
    printf("%d\n", ret);

    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%s", &N, S);
     ~~~~~^~~~~~~~~~~~~~~
# 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 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 1 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 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 640 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 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 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 1 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 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 640 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 4 ms 2304 KB Output is correct
19 Correct 3 ms 1920 KB Output is correct
20 Correct 4 ms 2304 KB Output is correct
21 Correct 4 ms 2432 KB Output is correct
22 Correct 3 ms 1664 KB Output is correct
23 Correct 4 ms 2176 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 5 ms 3968 KB Output is correct
26 Correct 5 ms 4224 KB Output is correct
27 Correct 4 ms 3072 KB Output is correct
28 Correct 4 ms 2432 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 2 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 3840 KB Output is correct
34 Correct 4 ms 3584 KB Output is correct
35 Correct 4 ms 2736 KB Output is correct
36 Correct 3 ms 1920 KB Output is correct
37 Correct 3 ms 1664 KB Output is correct
38 Correct 3 ms 2176 KB Output is correct
39 Correct 3 ms 2304 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 3 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 106 ms 162956 KB Output is correct
3 Correct 107 ms 162168 KB Output is correct
4 Correct 127 ms 162944 KB Output is correct
5 Correct 118 ms 163028 KB Output is correct
6 Correct 118 ms 162952 KB Output is correct
7 Correct 116 ms 162100 KB Output is correct
8 Correct 110 ms 162168 KB Output is correct
9 Correct 109 ms 161408 KB Output is correct
10 Correct 104 ms 162932 KB Output is correct
11 Correct 105 ms 163128 KB Output is correct
12 Correct 31 ms 43984 KB Output is correct
13 Correct 49 ms 77220 KB Output is correct
14 Correct 93 ms 111352 KB Output is correct
15 Correct 106 ms 162952 KB Output is correct
16 Correct 99 ms 162908 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 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 1 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 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 640 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 4 ms 2304 KB Output is correct
19 Correct 3 ms 1920 KB Output is correct
20 Correct 4 ms 2304 KB Output is correct
21 Correct 4 ms 2432 KB Output is correct
22 Correct 3 ms 1664 KB Output is correct
23 Correct 4 ms 2176 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 5 ms 3968 KB Output is correct
26 Correct 5 ms 4224 KB Output is correct
27 Correct 4 ms 3072 KB Output is correct
28 Correct 4 ms 2432 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 2 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 3840 KB Output is correct
34 Correct 4 ms 3584 KB Output is correct
35 Correct 4 ms 2736 KB Output is correct
36 Correct 3 ms 1920 KB Output is correct
37 Correct 3 ms 1664 KB Output is correct
38 Correct 3 ms 2176 KB Output is correct
39 Correct 3 ms 2304 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 3 ms 2176 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 106 ms 162956 KB Output is correct
44 Correct 107 ms 162168 KB Output is correct
45 Correct 127 ms 162944 KB Output is correct
46 Correct 118 ms 163028 KB Output is correct
47 Correct 118 ms 162952 KB Output is correct
48 Correct 116 ms 162100 KB Output is correct
49 Correct 110 ms 162168 KB Output is correct
50 Correct 109 ms 161408 KB Output is correct
51 Correct 104 ms 162932 KB Output is correct
52 Correct 105 ms 163128 KB Output is correct
53 Correct 31 ms 43984 KB Output is correct
54 Correct 49 ms 77220 KB Output is correct
55 Correct 93 ms 111352 KB Output is correct
56 Correct 106 ms 162952 KB Output is correct
57 Correct 99 ms 162908 KB Output is correct
58 Correct 88 ms 75584 KB Output is correct
59 Correct 103 ms 95768 KB Output is correct
60 Correct 100 ms 86908 KB Output is correct
61 Correct 94 ms 84088 KB Output is correct
62 Correct 121 ms 160688 KB Output is correct
63 Correct 110 ms 160220 KB Output is correct
64 Correct 119 ms 150140 KB Output is correct
65 Correct 121 ms 138616 KB Output is correct
66 Correct 119 ms 85308 KB Output is correct
67 Correct 106 ms 82148 KB Output is correct
68 Correct 100 ms 87928 KB Output is correct
69 Correct 104 ms 84572 KB Output is correct
70 Correct 100 ms 91640 KB Output is correct
71 Correct 113 ms 83192 KB Output is correct
72 Correct 41 ms 41216 KB Output is correct
73 Correct 6 ms 2816 KB Output is correct