Submission #167298

# Submission time Handle Problem Language Result Execution time Memory
167298 2019-12-07T08:36:19 Z combi1k1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
161 ms 95884 KB
#include<bits/stdc++.h>

using namespace std;

#define sz(x)   (int)x.size()

const int   N   = 201;

int f[N][N][N][3];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;      cin >> n;
    string s;   cin >> s;

    vector<int> pos[3];
    vector<int> ord[3];

    for(int i = 0 ; i < n ; ++i)    {
        if (s[i] == 'R')    pos[0].push_back(i + 1);
        if (s[i] == 'G')    pos[1].push_back(i + 1);
        if (s[i] == 'Y')    pos[2].push_back(i + 1);
    }

    if (sz(pos[0]) > (n + 1) / 2)   return  0 * puts("-1");
    if (sz(pos[1]) > (n + 1) / 2)   return  0 * puts("-1");
    if (sz(pos[2]) > (n + 1) / 2)   return  0 * puts("-1");

    memset(f,0x3f3f3f3f,sizeof f);

    if (sz(pos[0]))     f[1][0][0][0] = pos[0][0] - 1;
    if (sz(pos[1]))     f[0][1][0][1] = pos[1][0] - 1;
    if (sz(pos[2]))     f[0][0][1][2] = pos[2][0] - 1;

    for(int i = 0 ; i < 3 ; ++i)    {

        for(int j = 0 ; j <= n ; ++j)
        ord[i].push_back(upper_bound(pos[i].begin(),pos[i].end(),j) - pos[i].begin());
        pos[i].insert(pos[i].begin(),0);
    }

    for(int a = 0 ; a < sz(pos[0]) ; ++a)
    for(int b = 0 ; b < sz(pos[1]) ; ++b)
    for(int c = 0 ; c < sz(pos[2]) ; ++c)    {
        int P = a + b + c;
        if (P < 2)  continue;

        for(int x = 0 ; x < 3 ; ++x)    {
            int na = a - (x == 0);
            int nb = b - (x == 1);
            int nc = c - (x == 2);

            if (na < 0) continue;
            if (nb < 0) continue;
            if (nc < 0) continue;

            int real_pos;

            if (x == 0) real_pos = pos[0][a] + max(0,b - ord[1][pos[0][a]]) + max(0,c - ord[2][pos[0][a]]);
            if (x == 1) real_pos = pos[1][b] + max(0,a - ord[0][pos[1][b]]) + max(0,c - ord[2][pos[1][b]]);
            if (x == 2) real_pos = pos[2][c] + max(0,a - ord[0][pos[2][c]]) + max(0,b - ord[1][pos[2][c]]);

            f[a][b][c][x] = min(f[na][nb][nc][0 + (x == 0)],f[na][nb][nc][2 - (x == 2)]) + abs(real_pos - P);
        }
    }

    int ans = 0x3f3f3f3f;

    ans = min(ans,f[pos[0].size() - 1][pos[1].size() - 1][pos[2].size() - 1][0]);
    ans = min(ans,f[pos[0].size() - 1][pos[1].size() - 1][pos[2].size() - 1][1]);
    ans = min(ans,f[pos[0].size() - 1][pos[1].size() - 1][pos[2].size() - 1][2]);

    cout << ans << endl;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:65:105: warning: 'real_pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
             f[a][b][c][x] = min(f[na][nb][nc][0 + (x == 0)],f[na][nb][nc][2 - (x == 2)]) + abs(real_pos - P);
                                                                                                ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 84 ms 95608 KB Output is correct
2 Correct 93 ms 95736 KB Output is correct
3 Correct 87 ms 95736 KB Output is correct
4 Correct 84 ms 95796 KB Output is correct
5 Correct 86 ms 95736 KB Output is correct
6 Correct 83 ms 95708 KB Output is correct
7 Correct 87 ms 95736 KB Output is correct
8 Correct 86 ms 95680 KB Output is correct
9 Correct 83 ms 95736 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 85 ms 95692 KB Output is correct
12 Correct 84 ms 95736 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 93 ms 95708 KB Output is correct
15 Correct 84 ms 95736 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 95608 KB Output is correct
2 Correct 93 ms 95736 KB Output is correct
3 Correct 87 ms 95736 KB Output is correct
4 Correct 84 ms 95796 KB Output is correct
5 Correct 86 ms 95736 KB Output is correct
6 Correct 83 ms 95708 KB Output is correct
7 Correct 87 ms 95736 KB Output is correct
8 Correct 86 ms 95680 KB Output is correct
9 Correct 83 ms 95736 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 85 ms 95692 KB Output is correct
12 Correct 84 ms 95736 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 93 ms 95708 KB Output is correct
15 Correct 84 ms 95736 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 94 ms 95648 KB Output is correct
19 Correct 83 ms 95736 KB Output is correct
20 Correct 84 ms 95600 KB Output is correct
21 Correct 84 ms 95732 KB Output is correct
22 Correct 84 ms 95736 KB Output is correct
23 Correct 83 ms 95608 KB Output is correct
24 Correct 85 ms 95680 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 85 ms 95752 KB Output is correct
28 Correct 83 ms 95608 KB Output is correct
29 Correct 85 ms 95736 KB Output is correct
30 Correct 84 ms 95736 KB Output is correct
31 Correct 85 ms 95608 KB Output is correct
32 Correct 161 ms 95736 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 84 ms 95608 KB Output is correct
36 Correct 94 ms 95608 KB Output is correct
37 Correct 83 ms 95608 KB Output is correct
38 Correct 94 ms 95608 KB Output is correct
39 Correct 84 ms 95736 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 95600 KB Output is correct
2 Correct 90 ms 95664 KB Output is correct
3 Correct 89 ms 95736 KB Output is correct
4 Correct 100 ms 95736 KB Output is correct
5 Correct 90 ms 95864 KB Output is correct
6 Correct 89 ms 95732 KB Output is correct
7 Correct 90 ms 95736 KB Output is correct
8 Correct 89 ms 95736 KB Output is correct
9 Correct 91 ms 95656 KB Output is correct
10 Correct 88 ms 95736 KB Output is correct
11 Correct 89 ms 95704 KB Output is correct
12 Correct 86 ms 95796 KB Output is correct
13 Correct 85 ms 95736 KB Output is correct
14 Correct 87 ms 95736 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 95608 KB Output is correct
2 Correct 93 ms 95736 KB Output is correct
3 Correct 87 ms 95736 KB Output is correct
4 Correct 84 ms 95796 KB Output is correct
5 Correct 86 ms 95736 KB Output is correct
6 Correct 83 ms 95708 KB Output is correct
7 Correct 87 ms 95736 KB Output is correct
8 Correct 86 ms 95680 KB Output is correct
9 Correct 83 ms 95736 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 85 ms 95692 KB Output is correct
12 Correct 84 ms 95736 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 93 ms 95708 KB Output is correct
15 Correct 84 ms 95736 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 94 ms 95648 KB Output is correct
19 Correct 83 ms 95736 KB Output is correct
20 Correct 84 ms 95600 KB Output is correct
21 Correct 84 ms 95732 KB Output is correct
22 Correct 84 ms 95736 KB Output is correct
23 Correct 83 ms 95608 KB Output is correct
24 Correct 85 ms 95680 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 85 ms 95752 KB Output is correct
28 Correct 83 ms 95608 KB Output is correct
29 Correct 85 ms 95736 KB Output is correct
30 Correct 84 ms 95736 KB Output is correct
31 Correct 85 ms 95608 KB Output is correct
32 Correct 161 ms 95736 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 84 ms 95608 KB Output is correct
36 Correct 94 ms 95608 KB Output is correct
37 Correct 83 ms 95608 KB Output is correct
38 Correct 94 ms 95608 KB Output is correct
39 Correct 84 ms 95736 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 83 ms 95600 KB Output is correct
43 Correct 90 ms 95664 KB Output is correct
44 Correct 89 ms 95736 KB Output is correct
45 Correct 100 ms 95736 KB Output is correct
46 Correct 90 ms 95864 KB Output is correct
47 Correct 89 ms 95732 KB Output is correct
48 Correct 90 ms 95736 KB Output is correct
49 Correct 89 ms 95736 KB Output is correct
50 Correct 91 ms 95656 KB Output is correct
51 Correct 88 ms 95736 KB Output is correct
52 Correct 89 ms 95704 KB Output is correct
53 Correct 86 ms 95796 KB Output is correct
54 Correct 85 ms 95736 KB Output is correct
55 Correct 87 ms 95736 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 147 ms 95680 KB Output is correct
59 Correct 151 ms 95772 KB Output is correct
60 Correct 146 ms 95652 KB Output is correct
61 Correct 146 ms 95628 KB Output is correct
62 Correct 2 ms 348 KB Output is correct
63 Correct 120 ms 95668 KB Output is correct
64 Correct 123 ms 95884 KB Output is correct
65 Correct 132 ms 95700 KB Output is correct
66 Correct 146 ms 95736 KB Output is correct
67 Correct 148 ms 95656 KB Output is correct
68 Correct 151 ms 95704 KB Output is correct
69 Correct 150 ms 95820 KB Output is correct
70 Correct 149 ms 95668 KB Output is correct
71 Correct 149 ms 95716 KB Output is correct
72 Correct 2 ms 376 KB Output is correct
73 Correct 2 ms 376 KB Output is correct