Submission #122997

# Submission time Handle Problem Language Result Execution time Memory
122997 2019-06-29T23:21:39 Z zoooma13 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
242 ms 31940 KB
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 402
#define INF 0x3f3f3f3f

int n;
string s;
vector <int> pos[3];

int root = -1;
int smlr[3][MAX_N][MAX_N];
vector<vector<vector<int>>> dp[3];
int solve(int t ,int p0 ,int p1 ,int p2){
    if(p0+p1+p2 == n)
		return 0;
    int&ret = (~t ? dp[t][p0][p1][p2] : root);
    if(~ret)
        return ret;
    ret = INF;

    int st[] = {p0 ,p1 ,p2};
    for(int nt=0; nt<3; nt++)
        if(t != nt && st[nt] < pos[nt].size()){
            int cost = 0;
			for(int h=0; h<3; h++) if(h != nt)
				cost += smlr[h][st[h]][pos[nt][st[nt]]];

			st[nt]++;
            ret = min(ret ,cost+solve(nt ,st[0] ,st[1] ,st[2]));
            st[nt]--;
        }
    return ret;
}

int main()
{
    cin >> n;
    cin >> s;

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

    for(int i=0; i<3; i++)
        dp[i].resize(pos[0].size()+1 ,vector<vector<int>>(pos[1].size()+1 ,vector<int>(pos[2].size()+1 ,-1)));

    for(int t=0; t<3; t++)
    for(int i=0; i<pos[t].size(); i++){
        int pt_ptr = i;
        for(int j=0; j<n; j++){
            while(pt_ptr < pos[t].size() && pos[t][pt_ptr] <= j)
                pt_ptr++;
            smlr[t][i][j] = pt_ptr-i;
        }
    }

    root = -1 ,solve(-1 ,0 ,0 ,0);
    cout << (root == INF ? -1 : root) << endl;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int solve(int, int, int, int)':
joi2019_ho_t3.cpp:24:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(t != nt && st[nt] < pos[nt].size()){
                       ~~~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<pos[t].size(); i++){
                  ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:54:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(pt_ptr < pos[t].size() && pos[t][pt_ptr] <= j)
                   ~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 632 KB Output is correct
19 Correct 3 ms 608 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 508 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 612 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 632 KB Output is correct
32 Correct 2 ms 632 KB Output is correct
33 Correct 2 ms 632 KB Output is correct
34 Correct 2 ms 632 KB Output is correct
35 Correct 2 ms 632 KB Output is correct
36 Correct 2 ms 632 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 2 ms 632 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 13 ms 7672 KB Output is correct
3 Correct 17 ms 7544 KB Output is correct
4 Correct 17 ms 7672 KB Output is correct
5 Correct 13 ms 7672 KB Output is correct
6 Correct 15 ms 7672 KB Output is correct
7 Correct 15 ms 7672 KB Output is correct
8 Correct 15 ms 7672 KB Output is correct
9 Correct 15 ms 7548 KB Output is correct
10 Correct 15 ms 7672 KB Output is correct
11 Correct 16 ms 7804 KB Output is correct
12 Correct 6 ms 2424 KB Output is correct
13 Correct 11 ms 3960 KB Output is correct
14 Correct 10 ms 5496 KB Output is correct
15 Correct 13 ms 7672 KB Output is correct
16 Correct 13 ms 7672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 632 KB Output is correct
19 Correct 3 ms 608 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 508 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 612 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 632 KB Output is correct
32 Correct 2 ms 632 KB Output is correct
33 Correct 2 ms 632 KB Output is correct
34 Correct 2 ms 632 KB Output is correct
35 Correct 2 ms 632 KB Output is correct
36 Correct 2 ms 632 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 2 ms 632 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 13 ms 7672 KB Output is correct
44 Correct 17 ms 7544 KB Output is correct
45 Correct 17 ms 7672 KB Output is correct
46 Correct 13 ms 7672 KB Output is correct
47 Correct 15 ms 7672 KB Output is correct
48 Correct 15 ms 7672 KB Output is correct
49 Correct 15 ms 7672 KB Output is correct
50 Correct 15 ms 7548 KB Output is correct
51 Correct 15 ms 7672 KB Output is correct
52 Correct 16 ms 7804 KB Output is correct
53 Correct 6 ms 2424 KB Output is correct
54 Correct 11 ms 3960 KB Output is correct
55 Correct 10 ms 5496 KB Output is correct
56 Correct 13 ms 7672 KB Output is correct
57 Correct 13 ms 7672 KB Output is correct
58 Correct 242 ms 31456 KB Output is correct
59 Correct 212 ms 31940 KB Output is correct
60 Correct 219 ms 30712 KB Output is correct
61 Correct 214 ms 31488 KB Output is correct
62 Correct 14 ms 7416 KB Output is correct
63 Correct 16 ms 9208 KB Output is correct
64 Correct 52 ms 19320 KB Output is correct
65 Correct 98 ms 23912 KB Output is correct
66 Correct 209 ms 31096 KB Output is correct
67 Correct 203 ms 30764 KB Output is correct
68 Correct 217 ms 31136 KB Output is correct
69 Correct 221 ms 31736 KB Output is correct
70 Correct 216 ms 31480 KB Output is correct
71 Correct 201 ms 31100 KB Output is correct
72 Correct 17 ms 9084 KB Output is correct
73 Correct 5 ms 3064 KB Output is correct