Submission #100574

# Submission time Handle Problem Language Result Execution time Memory
100574 2019-03-12T11:09:23 Z ainta Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
60 / 100
500 ms 378724 KB
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, Num[200], C[3], V[410][3];
vector<int>U[3];
char p[410];
int D[410][410][410][3];
int main() {
	int i, j, k;
	Num['R'] = 0;
	Num['G'] = 1;
	Num['Y'] = 2;
	scanf("%d", &n);
	scanf("%s", p + 1);
	for (i = 1; i <= n; i++) {
		U[Num[p[i]]].push_back(i);
		V[i][0] = U[0].size();
		V[i][1] = U[1].size();
		V[i][2] = U[2].size();
	}
	for (i = 0; i < 3; i++)C[i] = U[i].size();
	for (i = 0; i <= n; i++) {
		for (j = 0; j <= i; j++) {
			for (k = 0; j+k <= i; k++) {
				D[i][j][k][0]=D[i][j][k][1]=D[i][j][k][2] = 1e9;
			}
		}
	}
	if (C[0])D[1][1][0][0] = 0;
	if (C[1])D[1][0][1][1] = 0;
	if (C[2])D[1][0][0][2] = 0;
	for (i = 1; i < n; i++) {
		for (j = 0; j <= i; j++) {
			for (k = 0; j+k <= i; k++) {
				int l = i - j - k;
				if (j > C[0] || k > C[1] || l > C[2])continue;
				for (int ii = 0; ii < 3; ii++) {
					int t = D[i][j][k][ii];
					if (t > 1e8)continue;
					if (ii!=0 && j != C[0]) {
						int tp = U[0][j];
						int s = max(k - V[tp][1], 0) + max(l - V[tp][2], 0);
						D[i + 1][j + 1][k][0] = min(D[i + 1][j + 1][k][0], t + s);
					}
					if (ii!=1 && k != C[1]) {
						int tp = U[1][k];
						int s = max(j - V[tp][0], 0) + max(l - V[tp][2], 0);
						D[i + 1][j][k + 1][1] = min(D[i + 1][j][k + 1][1], t + s);
					}
					if (ii!=2 && l != C[2]) {
						int tp = U[2][l];
						int s = max(j -V[tp][0], 0) + max(k - V[tp][1], 0);
						D[i + 1][j][k][2] = min(D[i + 1][j][k][2], t + s);
					}
				}
			}
		}
	}
	int res = 1e9;
	for (i = 0; i < 3; i++) {
		res = min(res, D[n][C[0]][C[1]][i]);
	}
	if (res > 1e8) {
		puts("-1");
	}
	else {
		printf("%d\n", res);
	}
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:17:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   U[Num[p[i]]].push_back(i);
             ^
joi2019_ho_t3.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", p + 1);
  ~~~~~^~~~~~~~~~~~~
# 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 2 ms 640 KB Output is correct
5 Correct 2 ms 896 KB Output is correct
6 Correct 3 ms 896 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 3 ms 896 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
13 Correct 2 ms 896 KB Output is correct
14 Correct 3 ms 896 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 3 ms 896 KB Output is correct
17 Correct 2 ms 896 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 2 ms 640 KB Output is correct
5 Correct 2 ms 896 KB Output is correct
6 Correct 3 ms 896 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 3 ms 896 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
13 Correct 2 ms 896 KB Output is correct
14 Correct 3 ms 896 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 3 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 9 ms 8576 KB Output is correct
19 Correct 9 ms 8576 KB Output is correct
20 Correct 8 ms 8620 KB Output is correct
21 Correct 7 ms 8576 KB Output is correct
22 Correct 8 ms 8576 KB Output is correct
23 Correct 10 ms 8576 KB Output is correct
24 Correct 8 ms 8576 KB Output is correct
25 Correct 10 ms 8576 KB Output is correct
26 Correct 8 ms 8576 KB Output is correct
27 Correct 7 ms 8576 KB Output is correct
28 Correct 8 ms 8576 KB Output is correct
29 Correct 8 ms 8576 KB Output is correct
30 Correct 7 ms 8576 KB Output is correct
31 Correct 9 ms 8704 KB Output is correct
32 Correct 9 ms 8576 KB Output is correct
33 Correct 9 ms 8320 KB Output is correct
34 Correct 9 ms 8320 KB Output is correct
35 Correct 7 ms 8064 KB Output is correct
36 Correct 9 ms 8320 KB Output is correct
37 Correct 9 ms 7808 KB Output is correct
38 Correct 9 ms 8576 KB Output is correct
39 Correct 8 ms 8576 KB Output is correct
40 Correct 37 ms 8292 KB Output is correct
41 Correct 8 ms 8564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Execution timed out 656 ms 378724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 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 2 ms 640 KB Output is correct
5 Correct 2 ms 896 KB Output is correct
6 Correct 3 ms 896 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
11 Correct 3 ms 896 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
13 Correct 2 ms 896 KB Output is correct
14 Correct 3 ms 896 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 3 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 9 ms 8576 KB Output is correct
19 Correct 9 ms 8576 KB Output is correct
20 Correct 8 ms 8620 KB Output is correct
21 Correct 7 ms 8576 KB Output is correct
22 Correct 8 ms 8576 KB Output is correct
23 Correct 10 ms 8576 KB Output is correct
24 Correct 8 ms 8576 KB Output is correct
25 Correct 10 ms 8576 KB Output is correct
26 Correct 8 ms 8576 KB Output is correct
27 Correct 7 ms 8576 KB Output is correct
28 Correct 8 ms 8576 KB Output is correct
29 Correct 8 ms 8576 KB Output is correct
30 Correct 7 ms 8576 KB Output is correct
31 Correct 9 ms 8704 KB Output is correct
32 Correct 9 ms 8576 KB Output is correct
33 Correct 9 ms 8320 KB Output is correct
34 Correct 9 ms 8320 KB Output is correct
35 Correct 7 ms 8064 KB Output is correct
36 Correct 9 ms 8320 KB Output is correct
37 Correct 9 ms 7808 KB Output is correct
38 Correct 9 ms 8576 KB Output is correct
39 Correct 8 ms 8576 KB Output is correct
40 Correct 37 ms 8292 KB Output is correct
41 Correct 8 ms 8564 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Execution timed out 656 ms 378724 KB Time limit exceeded
44 Halted 0 ms 0 KB -