Submission #170520

# Submission time Handle Problem Language Result Execution time Memory
170520 2019-12-25T14:42:09 Z stefdasca Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
339 ms 155768 KB
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

typedef long long ll;

int n;
string s;
vector<int> v[4];
int dp[402][402][402][3];
bool viz[402][402][402][3];
int sp[5][402];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    cin >> s;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'R')
            v[1].pb(i), sp[1][i]++;
        if(s[i] == 'G')
            v[2].pb(i), sp[2][i]++;
        if(s[i] == 'Y')
            v[3].pb(i), sp[3][i]++;
        if(i)
            for(int j = 1; j <= 3; ++j)
                sp[j][i] += sp[j][i-1];
    }
    viz[0][0][0][0] = viz[0][0][0][1] = viz[0][0][0][2] = 1;
    int mn = (1<<30);
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j <= i; ++j)
            for(int k = 0; k <= i; ++k)
                for(int lst = 0; lst <= 2; ++lst)
                {
                    if(!viz[i][j][k][lst])
                        continue;
                    int chR = j;
                    int chG = k;
                    int chY = i - j - k;
                    // next = rosu
                    if(chR < v[1].size() && lst != 0)
                    {
                        int realpos = v[1][chR];
                        if(chG > 0 && v[2][chG-1] > realpos)
                            realpos += sp[2][v[2][chG-1]] - sp[2][realpos];
                        if(chY > 0 && v[3][chY-1] > realpos)
                            realpos += sp[3][v[3][chY-1]] - sp[3][realpos];
                        if(!viz[i+1][j+1][k][0] || dp[i+1][j+1][k][0] > dp[i][j][k][lst] + max(0, realpos - i))
                        {
                            dp[i+1][j+1][k][0] = dp[i][j][k][lst] + max(0, realpos - i);
                            viz[i+1][j+1][k][0] = 1;
                        }
                    }
                    if(chG < v[2].size() && lst != 1)
                    {
                        int realpos = v[2][chG];
                        if(chR > 0 && v[1][chR-1] > realpos)
                            realpos += sp[1][v[1][chR-1]] - sp[1][realpos];
                        if(chY > 0 && v[3][chY-1] > realpos)
                            realpos += sp[3][v[3][chY-1]] - sp[3][realpos];
                        if(!viz[i+1][j][k+1][1] || dp[i+1][j][k+1][1] > dp[i][j][k][lst] + max(0, realpos - i))
                        {
                            dp[i+1][j][k+1][1] = dp[i][j][k][lst] + max(0, realpos - i);
                            viz[i+1][j][k+1][1] = 1;
                        }
                    }
                    if(chY < v[3].size() && lst != 2)
                    {
                        int realpos = v[3][chY];
                        if(chR > 0 && v[1][chR-1] > realpos)
                            realpos += sp[1][v[1][chR-1]] - sp[1][realpos];
                        if(chG > 0 && v[2][chG-1] > realpos)
                            realpos += sp[2][v[2][chG-1]] - sp[2][realpos];
                        if(!viz[i+1][j][k][2] || dp[i+1][j][k][2] > dp[i][j][k][lst] + max(0, realpos - i))
                        {
                            dp[i+1][j][k][2] = dp[i][j][k][lst] + max(0, realpos - i);
                            viz[i+1][j][k][2] = 1;
                        }
                    }
                }
    }
    for(int i = 0; i <= 2; ++i)
        if(viz[n][(int)v[1].size()][(int)v[2].size()][i])
            mn = min(mn, dp[n][(int)v[1].size()][(int)v[2].size()][i]);
    if(mn == (1<<30))
        mn = -1;
    cout << mn;
    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:54:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if(chR < v[1].size() && lst != 0)
                        ~~~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:67:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if(chG < v[2].size() && lst != 1)
                        ~~~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:80:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if(chY < v[3].size() && lst != 2)
                        ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 2 ms 788 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 2 ms 788 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 6 ms 4216 KB Output is correct
19 Correct 6 ms 4220 KB Output is correct
20 Correct 6 ms 4088 KB Output is correct
21 Correct 6 ms 4344 KB Output is correct
22 Correct 6 ms 3704 KB Output is correct
23 Correct 6 ms 4216 KB Output is correct
24 Correct 5 ms 3448 KB Output is correct
25 Correct 4 ms 1272 KB Output is correct
26 Correct 4 ms 1532 KB Output is correct
27 Correct 6 ms 3704 KB Output is correct
28 Correct 6 ms 4344 KB Output is correct
29 Correct 6 ms 4344 KB Output is correct
30 Correct 6 ms 4208 KB Output is correct
31 Correct 6 ms 4088 KB Output is correct
32 Correct 6 ms 4136 KB Output is correct
33 Correct 4 ms 1784 KB Output is correct
34 Correct 4 ms 2044 KB Output is correct
35 Correct 6 ms 3832 KB Output is correct
36 Correct 6 ms 4088 KB Output is correct
37 Correct 5 ms 3576 KB Output is correct
38 Correct 6 ms 3832 KB Output is correct
39 Correct 6 ms 4344 KB Output is correct
40 Correct 3 ms 888 KB Output is correct
41 Correct 4 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 142 ms 6364 KB Output is correct
3 Correct 141 ms 6392 KB Output is correct
4 Correct 149 ms 6560 KB Output is correct
5 Correct 142 ms 6392 KB Output is correct
6 Correct 142 ms 6432 KB Output is correct
7 Correct 142 ms 6392 KB Output is correct
8 Correct 141 ms 6368 KB Output is correct
9 Correct 140 ms 6540 KB Output is correct
10 Correct 143 ms 6684 KB Output is correct
11 Correct 142 ms 6376 KB Output is correct
12 Correct 27 ms 3492 KB Output is correct
13 Correct 54 ms 4600 KB Output is correct
14 Correct 86 ms 5392 KB Output is correct
15 Correct 142 ms 6440 KB Output is correct
16 Correct 142 ms 6412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 2 ms 788 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 6 ms 4216 KB Output is correct
19 Correct 6 ms 4220 KB Output is correct
20 Correct 6 ms 4088 KB Output is correct
21 Correct 6 ms 4344 KB Output is correct
22 Correct 6 ms 3704 KB Output is correct
23 Correct 6 ms 4216 KB Output is correct
24 Correct 5 ms 3448 KB Output is correct
25 Correct 4 ms 1272 KB Output is correct
26 Correct 4 ms 1532 KB Output is correct
27 Correct 6 ms 3704 KB Output is correct
28 Correct 6 ms 4344 KB Output is correct
29 Correct 6 ms 4344 KB Output is correct
30 Correct 6 ms 4208 KB Output is correct
31 Correct 6 ms 4088 KB Output is correct
32 Correct 6 ms 4136 KB Output is correct
33 Correct 4 ms 1784 KB Output is correct
34 Correct 4 ms 2044 KB Output is correct
35 Correct 6 ms 3832 KB Output is correct
36 Correct 6 ms 4088 KB Output is correct
37 Correct 5 ms 3576 KB Output is correct
38 Correct 6 ms 3832 KB Output is correct
39 Correct 6 ms 4344 KB Output is correct
40 Correct 3 ms 888 KB Output is correct
41 Correct 4 ms 1400 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 142 ms 6364 KB Output is correct
44 Correct 141 ms 6392 KB Output is correct
45 Correct 149 ms 6560 KB Output is correct
46 Correct 142 ms 6392 KB Output is correct
47 Correct 142 ms 6432 KB Output is correct
48 Correct 142 ms 6392 KB Output is correct
49 Correct 141 ms 6368 KB Output is correct
50 Correct 140 ms 6540 KB Output is correct
51 Correct 143 ms 6684 KB Output is correct
52 Correct 142 ms 6376 KB Output is correct
53 Correct 27 ms 3492 KB Output is correct
54 Correct 54 ms 4600 KB Output is correct
55 Correct 86 ms 5392 KB Output is correct
56 Correct 142 ms 6440 KB Output is correct
57 Correct 142 ms 6412 KB Output is correct
58 Correct 283 ms 153240 KB Output is correct
59 Correct 284 ms 153720 KB Output is correct
60 Correct 283 ms 153464 KB Output is correct
61 Correct 285 ms 154876 KB Output is correct
62 Correct 148 ms 13688 KB Output is correct
63 Correct 153 ms 22692 KB Output is correct
64 Correct 196 ms 70008 KB Output is correct
65 Correct 231 ms 102676 KB Output is correct
66 Correct 339 ms 153548 KB Output is correct
67 Correct 281 ms 150904 KB Output is correct
68 Correct 306 ms 154872 KB Output is correct
69 Correct 302 ms 155768 KB Output is correct
70 Correct 284 ms 154904 KB Output is correct
71 Correct 298 ms 151156 KB Output is correct
72 Correct 157 ms 23920 KB Output is correct
73 Correct 146 ms 7704 KB Output is correct