Submission #98031

# Submission time Handle Problem Language Result Execution time Memory
98031 2019-02-19T22:30:16 Z giorgikob Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
138 ms 163196 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
using namespace std;

const int N = 5e5+5;

ll n, m, k, x, y, a, b, t, q, ans, sum;

vector< ll > g_ind, r_ind, y_ind;

ll A[N],B[N];
char C[N];

int G,R,Y;
int g_num[N], r_num[N], y_num[N];
int ind;

int dp[405][405][405][4];

int calc(int x,int y){
	
	if(x==-1 && y==-1)return -1;
	if(x==-1)return y;
	if(y==-1)return x;
	
	return min(x,y);
}

int main()
{
	ios::sync_with_stdio(0);
	
	g_ind.push_back(0);
	r_ind.push_back(0);
	y_ind.push_back(0);
	
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> C[i];
		
		g_num[i] = g_num[i-1];
		r_num[i] = r_num[i-1];
		y_num[i] = y_num[i-1];
		
		if( C[i] == 'G' ){
			g_ind.push_back(i);
			G++;
			g_num[i]++;
		}
		
		if( C[i] == 'R' ){
			r_ind.push_back(i);
			R++;
			r_num[i]++;
		}
		
		if( C[i] == 'Y' ){
			y_ind.push_back(i);
			Y++;
			y_num[i]++;
		}
	}
	
	for(int g = 0; g <= G; g++ )
		for(int r = 0; r <= R; r++ )
			for(int y = 0; y <= Y; y++ )
			for(int i=1;i<=3;i++)
			dp[g][r][y][i]=-1;
	
	for(int i=1;i<=3;i++)
	dp[0][0][0][i]=0;
	
	for(int g = 0; g <= G; g++ )
		for(int r = 0; r <= R; r++ )
			for(int y = 0; y <= Y; y++ ){
				
				int sul = g+r+y;
				sul++;
				sul /= 2;
				
				ind = g_ind[g];
				
				if(  g>0 && g<=sul ){
					int z = calc( dp[g - 1][r][y][2] , dp[g - 1][r][y][3] );
					if(z!=-1)
					dp[g][r][y][1] = z + max(0,(r_num[ind] - r_num[r_ind[r]])) + max(0,(y_num[ind] - y_num[y_ind[y]]));  	
				}
				
				ind = r_ind[r];
				
				if( r>0 && r<=sul ){
					int z = calc( dp[g][r - 1][y][1] , dp[g][r - 1][y][3] );
					if(z!=-1)
					dp[g][r][y][2] = z + max(0,(g_num[ind] - g_num[g_ind[g]])) + max(0,(y_num[ind] - y_num[y_ind[y]]));  	
				}
				
				ind = y_ind[y];
				
				if( y>0 && y<=sul ){
					int z = calc( dp[g][r][y - 1][1] , dp[g][r][y - 1][2] );
					if(z!=-1)
					dp[g][r][y][3] = z + max(0,(g_num[ind] - g_num[g_ind[g]])) + max(0,(r_num[ind] - r_num[r_ind[r]]));  	
				}
				
			//	cout << dp[g][r][y][1] <<" "<< dp[g][r][y][2] <<" "<< dp[g][r][y][3] << endl;
			//	cout<<g<<" "<<r<<" "<<y<<endl;
			//	cout<<endl;
			}
			
			
	cout << calc( dp[G][R][Y][1] , calc( dp[G][R][Y][2] , dp[G][R][Y][3] ) ) << endl;
}





# 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 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 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 2 ms 384 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 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 3 ms 2048 KB Output is correct
20 Correct 4 ms 2304 KB Output is correct
21 Correct 5 ms 2596 KB Output is correct
22 Correct 3 ms 1792 KB Output is correct
23 Correct 3 ms 2304 KB Output is correct
24 Correct 3 ms 1792 KB Output is correct
25 Correct 4 ms 3968 KB Output is correct
26 Correct 6 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 2176 KB Output is correct
32 Correct 3 ms 2432 KB Output is correct
33 Correct 4 ms 4096 KB Output is correct
34 Correct 4 ms 3712 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 1920 KB Output is correct
38 Correct 3 ms 2304 KB Output is correct
39 Correct 4 ms 2432 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 4 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 109 ms 162936 KB Output is correct
3 Correct 110 ms 162164 KB Output is correct
4 Correct 124 ms 163096 KB Output is correct
5 Correct 113 ms 162976 KB Output is correct
6 Correct 138 ms 162936 KB Output is correct
7 Correct 120 ms 162204 KB Output is correct
8 Correct 115 ms 162100 KB Output is correct
9 Correct 112 ms 161412 KB Output is correct
10 Correct 115 ms 163004 KB Output is correct
11 Correct 111 ms 163196 KB Output is correct
12 Correct 34 ms 44132 KB Output is correct
13 Correct 56 ms 77176 KB Output is correct
14 Correct 74 ms 111480 KB Output is correct
15 Correct 110 ms 163064 KB Output is correct
16 Correct 109 ms 162936 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 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 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 3 ms 2048 KB Output is correct
20 Correct 4 ms 2304 KB Output is correct
21 Correct 5 ms 2596 KB Output is correct
22 Correct 3 ms 1792 KB Output is correct
23 Correct 3 ms 2304 KB Output is correct
24 Correct 3 ms 1792 KB Output is correct
25 Correct 4 ms 3968 KB Output is correct
26 Correct 6 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 2176 KB Output is correct
32 Correct 3 ms 2432 KB Output is correct
33 Correct 4 ms 4096 KB Output is correct
34 Correct 4 ms 3712 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 1920 KB Output is correct
38 Correct 3 ms 2304 KB Output is correct
39 Correct 4 ms 2432 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 4 ms 2432 KB Output is correct
42 Correct 2 ms 428 KB Output is correct
43 Correct 109 ms 162936 KB Output is correct
44 Correct 110 ms 162164 KB Output is correct
45 Correct 124 ms 163096 KB Output is correct
46 Correct 113 ms 162976 KB Output is correct
47 Correct 138 ms 162936 KB Output is correct
48 Correct 120 ms 162204 KB Output is correct
49 Correct 115 ms 162100 KB Output is correct
50 Correct 112 ms 161412 KB Output is correct
51 Correct 115 ms 163004 KB Output is correct
52 Correct 111 ms 163196 KB Output is correct
53 Correct 34 ms 44132 KB Output is correct
54 Correct 56 ms 77176 KB Output is correct
55 Correct 74 ms 111480 KB Output is correct
56 Correct 110 ms 163064 KB Output is correct
57 Correct 109 ms 162936 KB Output is correct
58 Correct 94 ms 101444 KB Output is correct
59 Correct 122 ms 119032 KB Output is correct
60 Correct 104 ms 111176 KB Output is correct
61 Correct 97 ms 109044 KB Output is correct
62 Correct 116 ms 161100 KB Output is correct
63 Correct 117 ms 161464 KB Output is correct
64 Correct 121 ms 154616 KB Output is correct
65 Correct 124 ms 145272 KB Output is correct
66 Correct 112 ms 109480 KB Output is correct
67 Correct 106 ms 107004 KB Output is correct
68 Correct 97 ms 112248 KB Output is correct
69 Correct 126 ms 109816 KB Output is correct
70 Correct 100 ms 115804 KB Output is correct
71 Correct 94 ms 107384 KB Output is correct
72 Correct 42 ms 43896 KB Output is correct
73 Correct 5 ms 4352 KB Output is correct