Submission #114831

# Submission time Handle Problem Language Result Execution time Memory
114831 2019-06-03T11:27:14 Z dsjong Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
187 ms 163064 KB
#include<bits/stdc++.h>
using namespace std;
int N,tr,tg,ty;
string s;
vector<int>cnt[4];
int dp[405][405][405][4];
int lol[405][4];
int go(int r,int g,int y,int l){
	if(dp[r][g][y][l]!=-1) return dp[r][g][y][l];
	int &ans=dp[r][g][y][l];
	int n=r+g+y;
	if(n==0) return 0;
	ans=1e9;
	int extras=0;
	if(l==1&&r>0){
		int lb1=min(g,lol[cnt[1][r-1]][2]);
		int lb2=min(y,lol[cnt[1][r-1]][3]);
		extras=g+y-lb1-lb2;
		int add=extras+cnt[1][r-1]-n+1;
		ans=min(ans,go(r-1,g,y,2)+add);
		ans=min(ans,go(r-1,g,y,3)+add);
	}
	else if(l==2&&g>0){
		int lb1=min(r,lol[cnt[2][g-1]][1]);
		int lb2=min(y,lol[cnt[2][g-1]][3]);
		extras=r+y-lb1-lb2;
		int add=extras+cnt[2][g-1]-n+1;
		ans=min(ans,go(r,g-1,y,1)+add);
		ans=min(ans,go(r,g-1,y,3)+add);
	}
	else if(l==3&&y>0){
		int lb1=min(r,lol[cnt[3][y-1]][1]);
		int lb2=min(g,lol[cnt[3][y-1]][2]);
		extras=g+r-lb1-lb2;
		int add=extras+cnt[3][y-1]-n+1;
		ans=min(ans,go(r,g,y-1,1)+add);
		ans=min(ans,go(r,g,y-1,2)+add);
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>N>>s;
	for(int i=0;i<N;i++){
		if(s[i]=='R'){
			tr++;
			cnt[1].push_back(i);
		}
		else if(s[i]=='G'){
			tg++;
			cnt[2].push_back(i);
		}
		else{
			ty++;
			cnt[3].push_back(i);
		}
	}
	for(int i=0;i<=tr;i++){
		for(int j=0;j<=tg;j++){
			for(int k=0;k<=ty;k++){
				for(int l=0;l<4;l++){
					dp[i][j][k][l]=-1;
				}
			}
		}
	}
	for(int t=1;t<=3;t++){
		int last=0;
		for(int i=0;i<cnt[t].size();i++){
			for(int j=last;j<=cnt[t][i];j++){
				lol[j][t]=i;
			}
			last=cnt[t][i]+1;
		}
		for(int j=last;j<=402;j++){
			lol[j][t]=cnt[t].size();
		}
	}
	int ans=min({go(tr,tg,ty,1),go(tr,tg,ty,2),go(tr,tg,ty,3)});
	if(ans==1e9||ans==-1) cout<<-1;
	else cout<<ans;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:71:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<cnt[t].size();i++){
               ~^~~~~~~~~~~~~~
# 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 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 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 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 384 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 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 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 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 4 ms 2432 KB Output is correct
19 Correct 4 ms 2012 KB Output is correct
20 Correct 7 ms 2304 KB Output is correct
21 Correct 4 ms 2432 KB Output is correct
22 Correct 3 ms 1792 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 3200 KB Output is correct
28 Correct 4 ms 2432 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 4 ms 2432 KB Output is correct
31 Correct 4 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 2816 KB Output is correct
36 Correct 4 ms 2048 KB Output is correct
37 Correct 3 ms 1792 KB Output is correct
38 Correct 4 ms 2176 KB Output is correct
39 Correct 4 ms 2432 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 4 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 121 ms 162936 KB Output is correct
3 Correct 110 ms 162184 KB Output is correct
4 Correct 111 ms 162984 KB Output is correct
5 Correct 109 ms 162908 KB Output is correct
6 Correct 110 ms 163016 KB Output is correct
7 Correct 112 ms 162168 KB Output is correct
8 Correct 109 ms 162172 KB Output is correct
9 Correct 107 ms 161400 KB Output is correct
10 Correct 134 ms 162936 KB Output is correct
11 Correct 110 ms 162940 KB Output is correct
12 Correct 32 ms 44152 KB Output is correct
13 Correct 54 ms 77304 KB Output is correct
14 Correct 77 ms 111480 KB Output is correct
15 Correct 109 ms 162936 KB Output is correct
16 Correct 116 ms 163064 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 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 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 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 4 ms 2432 KB Output is correct
19 Correct 4 ms 2012 KB Output is correct
20 Correct 7 ms 2304 KB Output is correct
21 Correct 4 ms 2432 KB Output is correct
22 Correct 3 ms 1792 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 3200 KB Output is correct
28 Correct 4 ms 2432 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 4 ms 2432 KB Output is correct
31 Correct 4 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 2816 KB Output is correct
36 Correct 4 ms 2048 KB Output is correct
37 Correct 3 ms 1792 KB Output is correct
38 Correct 4 ms 2176 KB Output is correct
39 Correct 4 ms 2432 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 4 ms 2304 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 121 ms 162936 KB Output is correct
44 Correct 110 ms 162184 KB Output is correct
45 Correct 111 ms 162984 KB Output is correct
46 Correct 109 ms 162908 KB Output is correct
47 Correct 110 ms 163016 KB Output is correct
48 Correct 112 ms 162168 KB Output is correct
49 Correct 109 ms 162172 KB Output is correct
50 Correct 107 ms 161400 KB Output is correct
51 Correct 134 ms 162936 KB Output is correct
52 Correct 110 ms 162940 KB Output is correct
53 Correct 32 ms 44152 KB Output is correct
54 Correct 54 ms 77304 KB Output is correct
55 Correct 77 ms 111480 KB Output is correct
56 Correct 109 ms 162936 KB Output is correct
57 Correct 116 ms 163064 KB Output is correct
58 Correct 168 ms 101500 KB Output is correct
59 Correct 183 ms 118936 KB Output is correct
60 Correct 183 ms 111224 KB Output is correct
61 Correct 186 ms 109176 KB Output is correct
62 Correct 115 ms 161272 KB Output is correct
63 Correct 118 ms 161416 KB Output is correct
64 Correct 121 ms 154616 KB Output is correct
65 Correct 138 ms 145260 KB Output is correct
66 Correct 181 ms 109560 KB Output is correct
67 Correct 177 ms 106744 KB Output is correct
68 Correct 182 ms 112376 KB Output is correct
69 Correct 185 ms 109824 KB Output is correct
70 Correct 187 ms 115752 KB Output is correct
71 Correct 180 ms 107640 KB Output is correct
72 Correct 37 ms 44920 KB Output is correct
73 Correct 5 ms 3712 KB Output is correct