Submission #199067

# Submission time Handle Problem Language Result Execution time Memory
199067 2020-01-29T04:25:40 Z mahmoudbadawy Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
367 ms 180124 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> pos[3];
int mem[404][404][404][3];
int vis[404][404][404][3];
int sum[404][3];
int n;
string s;

int go(int x,int y,int z,int las)
{
	if(x+y+z==n) return 0;
	int &ret=mem[x][y][z][las];
	if(vis[x][y][z][las]) return ret;
	vis[x][y][z][las]=1;
	ret=(1<<30);
	int cpos=x+y+z;
	if(x<pos[0].size()&&(las!=0||cpos==0))
	{
		int dif=0;
		dif+=max(sum[pos[0][x]][1]-y,0);
		dif+=max(sum[pos[0][x]][2]-z,0);
		ret=min(ret,go(x+1,y,z,0)+dif);
	}
	if(y<pos[1].size()&&(las!=1||cpos==0))
	{
		int dif=0;
		dif+=max(sum[pos[1][y]][0]-x,0);
		dif+=max(sum[pos[1][y]][2]-z,0);
		ret=min(ret,go(x,y+1,z,1)+dif);
	}
	if(z<pos[2].size()&&(las!=2||cpos==0))
	{
		int dif=0;
		dif+=max(sum[pos[2][z]][0]-x,0);
		dif+=max(sum[pos[2][z]][1]-y,0);
		ret=min(ret,go(x,y,z+1,2)+dif);
	}
	return ret;
}

int main()
{
	cin >> n >> s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R'){sum[i][0]++; pos[0].push_back(i);}
		else if(s[i]=='G') {sum[i][1]++; pos[1].push_back(i);}
		else {sum[i][2]++; pos[2].push_back(i);}
		if(i) for(int j=0;j<3;j++) sum[i][j]+=sum[i-1][j];
	}
	int ans=go(0,0,0,0);
	if(ans>=(1<<30)) ans=-1;
	cout << ans << endl;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int go(int, int, int, int)':
joi2019_ho_t3.cpp:20:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(x<pos[0].size()&&(las!=0||cpos==0))
     ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:27:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(y<pos[1].size()&&(las!=1||cpos==0))
     ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:34:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(z<pos[2].size()&&(las!=2||cpos==0))
     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 508 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 508 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 8 ms 4216 KB Output is correct
19 Correct 8 ms 3448 KB Output is correct
20 Correct 8 ms 4088 KB Output is correct
21 Correct 8 ms 4472 KB Output is correct
22 Correct 7 ms 2936 KB Output is correct
23 Correct 8 ms 3832 KB Output is correct
24 Correct 7 ms 2808 KB Output is correct
25 Correct 6 ms 1400 KB Output is correct
26 Correct 6 ms 1656 KB Output is correct
27 Correct 7 ms 4344 KB Output is correct
28 Correct 10 ms 4216 KB Output is correct
29 Correct 8 ms 4088 KB Output is correct
30 Correct 8 ms 4088 KB Output is correct
31 Correct 7 ms 3576 KB Output is correct
32 Correct 8 ms 4216 KB Output is correct
33 Correct 6 ms 1916 KB Output is correct
34 Correct 7 ms 2424 KB Output is correct
35 Correct 8 ms 4344 KB Output is correct
36 Correct 8 ms 3576 KB Output is correct
37 Correct 7 ms 3064 KB Output is correct
38 Correct 7 ms 3576 KB Output is correct
39 Correct 8 ms 4220 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 6 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 9 ms 6648 KB Output is correct
3 Correct 9 ms 6648 KB Output is correct
4 Correct 9 ms 6648 KB Output is correct
5 Correct 9 ms 6648 KB Output is correct
6 Correct 9 ms 6648 KB Output is correct
7 Correct 10 ms 6648 KB Output is correct
8 Correct 9 ms 6648 KB Output is correct
9 Correct 9 ms 6648 KB Output is correct
10 Correct 9 ms 6648 KB Output is correct
11 Correct 9 ms 6648 KB Output is correct
12 Correct 7 ms 3576 KB Output is correct
13 Correct 7 ms 4728 KB Output is correct
14 Correct 8 ms 5496 KB Output is correct
15 Correct 9 ms 6648 KB Output is correct
16 Correct 10 ms 6776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 508 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 8 ms 4216 KB Output is correct
19 Correct 8 ms 3448 KB Output is correct
20 Correct 8 ms 4088 KB Output is correct
21 Correct 8 ms 4472 KB Output is correct
22 Correct 7 ms 2936 KB Output is correct
23 Correct 8 ms 3832 KB Output is correct
24 Correct 7 ms 2808 KB Output is correct
25 Correct 6 ms 1400 KB Output is correct
26 Correct 6 ms 1656 KB Output is correct
27 Correct 7 ms 4344 KB Output is correct
28 Correct 10 ms 4216 KB Output is correct
29 Correct 8 ms 4088 KB Output is correct
30 Correct 8 ms 4088 KB Output is correct
31 Correct 7 ms 3576 KB Output is correct
32 Correct 8 ms 4216 KB Output is correct
33 Correct 6 ms 1916 KB Output is correct
34 Correct 7 ms 2424 KB Output is correct
35 Correct 8 ms 4344 KB Output is correct
36 Correct 8 ms 3576 KB Output is correct
37 Correct 7 ms 3064 KB Output is correct
38 Correct 7 ms 3576 KB Output is correct
39 Correct 8 ms 4220 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 6 ms 1400 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 9 ms 6648 KB Output is correct
44 Correct 9 ms 6648 KB Output is correct
45 Correct 9 ms 6648 KB Output is correct
46 Correct 9 ms 6648 KB Output is correct
47 Correct 9 ms 6648 KB Output is correct
48 Correct 10 ms 6648 KB Output is correct
49 Correct 9 ms 6648 KB Output is correct
50 Correct 9 ms 6648 KB Output is correct
51 Correct 9 ms 6648 KB Output is correct
52 Correct 9 ms 6648 KB Output is correct
53 Correct 7 ms 3576 KB Output is correct
54 Correct 7 ms 4728 KB Output is correct
55 Correct 8 ms 5496 KB Output is correct
56 Correct 9 ms 6648 KB Output is correct
57 Correct 10 ms 6776 KB Output is correct
58 Correct 330 ms 146680 KB Output is correct
59 Correct 295 ms 180124 KB Output is correct
60 Correct 313 ms 167904 KB Output is correct
61 Correct 321 ms 163120 KB Output is correct
62 Correct 17 ms 17912 KB Output is correct
63 Correct 25 ms 31352 KB Output is correct
64 Correct 85 ms 100984 KB Output is correct
65 Correct 150 ms 144120 KB Output is correct
66 Correct 305 ms 165240 KB Output is correct
67 Correct 367 ms 157792 KB Output is correct
68 Correct 332 ms 170012 KB Output is correct
69 Correct 314 ms 164300 KB Output is correct
70 Correct 287 ms 175612 KB Output is correct
71 Correct 293 ms 159736 KB Output is correct
72 Correct 230 ms 21752 KB Output is correct
73 Correct 8 ms 4728 KB Output is correct