Submission #263544

# Submission time Handle Problem Language Result Execution time Memory
263544 2020-08-13T19:19:06 Z sahil_k Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
60 / 100
500 ms 764804 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define MAXN 405
int n;
int a[MAXN];
vector<int> pos[3];
int dp[MAXN][MAXN][MAXN][3];
int o = 1e8;
int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	char ai;
	for (int i=1; i<=n; i++) {
		cin >> ai;
		if (ai == 'R') a[i] = 0;
		if (ai == 'G') a[i] = 1;
		if (ai == 'Y') a[i] = 2;
		pos[a[i]].push_back(i);
	}
	for (int i=1; i<=n; i++) {
		for (int j=0; j<=n; j++) {
			for (int k=0; k<=n; k++) {
				dp[i][j][k][0] = dp[i][j][k][1] = dp[i][j][k][2] = 1e8;
			}
		}
	}
	for (int i=1; i<=n; i++) {
		for (int j=0; j<=i/2+1; j++) {
			for (int k=0; k<=i-j; k++) {
				int l = i-j-k;
				if (j+k > i || j > pos[0].size() || k > pos[1].size() || l > pos[2].size()) continue;
				int score, cur;
				if (j > 0) {
					score = min(dp[i-1][j-1][k][1], dp[i-1][j-1][k][2]);
					cur = pos[0][j-1];
					cur += max(0l, k-(lower_bound(pos[1].begin(), pos[1].end(), pos[0][j-1])-pos[1].begin()));
					cur += max(0l, l-(lower_bound(pos[2].begin(), pos[2].end(), pos[0][j-1])-pos[2].begin()));
					score += abs(i-cur);
					dp[i][j][k][0] = min(dp[i][j][k][0], score);
				}
				if (k > 0) {
					score = min(dp[i-1][j][k-1][0], dp[i-1][j][k-1][2]);
					cur = pos[1][k-1];
					cur += max(0l, j-(lower_bound(pos[0].begin(), pos[0].end(), pos[1][k-1])-pos[0].begin()));
					cur += max(0l, l-(lower_bound(pos[2].begin(), pos[2].end(), pos[1][k-1])-pos[2].begin()));
					score += abs(i-cur);
					dp[i][j][k][1] = min(dp[i][j][k][1], score);
				}
				if (l > 0) {
					score = min(dp[i-1][j][k][0], dp[i-1][j][k][1]);
					cur = pos[2][l-1];
					cur += max(0l, j-(lower_bound(pos[0].begin(), pos[0].end(), pos[2][l-1])-pos[0].begin()));
					cur += max(0l, k-(lower_bound(pos[1].begin(), pos[1].end(), pos[2][l-1])-pos[1].begin()));
					score += abs(i-cur);
					dp[i][j][k][2] = min(dp[i][j][k][2], score);
				}
			}
		}
	}
	for (int j=0; j<=n; j++) {
		for (int k=0; k<=n; k++) {
			for (int e=0; e<3; e++) {
				o = min(o, dp[n][j][k][e]);
			}
		}
	}
	if (o == 1e8) {
		cout << -1 << endl;
	} else {
		cout << o << endl;
	}
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (j+k > i || j > pos[0].size() || k > pos[1].size() || l > pos[2].size()) continue;
      |                    ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:35:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (j+k > i || j > pos[0].size() || k > pos[1].size() || l > pos[2].size()) continue;
      |                                         ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:35:64: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (j+k > i || j > pos[0].size() || k > pos[1].size() || l > pos[2].size()) continue;
      |                                                              ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 1408 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
7 Correct 1 ms 1408 KB Output is correct
8 Correct 1 ms 1408 KB Output is correct
9 Correct 1 ms 1408 KB Output is correct
10 Correct 1 ms 1408 KB Output is correct
11 Correct 1 ms 1408 KB Output is correct
12 Correct 1 ms 1408 KB Output is correct
13 Correct 1 ms 1408 KB Output is correct
14 Correct 1 ms 1280 KB Output is correct
15 Correct 1 ms 1408 KB Output is correct
16 Correct 1 ms 1408 KB Output is correct
17 Correct 1 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 1408 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
7 Correct 1 ms 1408 KB Output is correct
8 Correct 1 ms 1408 KB Output is correct
9 Correct 1 ms 1408 KB Output is correct
10 Correct 1 ms 1408 KB Output is correct
11 Correct 1 ms 1408 KB Output is correct
12 Correct 1 ms 1408 KB Output is correct
13 Correct 1 ms 1408 KB Output is correct
14 Correct 1 ms 1280 KB Output is correct
15 Correct 1 ms 1408 KB Output is correct
16 Correct 1 ms 1408 KB Output is correct
17 Correct 1 ms 1280 KB Output is correct
18 Correct 11 ms 17792 KB Output is correct
19 Correct 10 ms 17792 KB Output is correct
20 Correct 10 ms 17920 KB Output is correct
21 Correct 10 ms 17792 KB Output is correct
22 Correct 10 ms 17792 KB Output is correct
23 Correct 13 ms 17792 KB Output is correct
24 Correct 11 ms 17792 KB Output is correct
25 Correct 12 ms 17792 KB Output is correct
26 Correct 11 ms 17792 KB Output is correct
27 Correct 12 ms 17792 KB Output is correct
28 Correct 11 ms 17792 KB Output is correct
29 Correct 14 ms 17792 KB Output is correct
30 Correct 13 ms 17920 KB Output is correct
31 Correct 14 ms 17792 KB Output is correct
32 Correct 14 ms 17792 KB Output is correct
33 Correct 13 ms 17152 KB Output is correct
34 Correct 10 ms 17152 KB Output is correct
35 Correct 10 ms 16640 KB Output is correct
36 Correct 10 ms 17152 KB Output is correct
37 Correct 10 ms 16000 KB Output is correct
38 Correct 10 ms 17792 KB Output is correct
39 Correct 10 ms 17792 KB Output is correct
40 Correct 9 ms 17152 KB Output is correct
41 Correct 10 ms 17792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 501 ms 764804 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 1408 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
7 Correct 1 ms 1408 KB Output is correct
8 Correct 1 ms 1408 KB Output is correct
9 Correct 1 ms 1408 KB Output is correct
10 Correct 1 ms 1408 KB Output is correct
11 Correct 1 ms 1408 KB Output is correct
12 Correct 1 ms 1408 KB Output is correct
13 Correct 1 ms 1408 KB Output is correct
14 Correct 1 ms 1280 KB Output is correct
15 Correct 1 ms 1408 KB Output is correct
16 Correct 1 ms 1408 KB Output is correct
17 Correct 1 ms 1280 KB Output is correct
18 Correct 11 ms 17792 KB Output is correct
19 Correct 10 ms 17792 KB Output is correct
20 Correct 10 ms 17920 KB Output is correct
21 Correct 10 ms 17792 KB Output is correct
22 Correct 10 ms 17792 KB Output is correct
23 Correct 13 ms 17792 KB Output is correct
24 Correct 11 ms 17792 KB Output is correct
25 Correct 12 ms 17792 KB Output is correct
26 Correct 11 ms 17792 KB Output is correct
27 Correct 12 ms 17792 KB Output is correct
28 Correct 11 ms 17792 KB Output is correct
29 Correct 14 ms 17792 KB Output is correct
30 Correct 13 ms 17920 KB Output is correct
31 Correct 14 ms 17792 KB Output is correct
32 Correct 14 ms 17792 KB Output is correct
33 Correct 13 ms 17152 KB Output is correct
34 Correct 10 ms 17152 KB Output is correct
35 Correct 10 ms 16640 KB Output is correct
36 Correct 10 ms 17152 KB Output is correct
37 Correct 10 ms 16000 KB Output is correct
38 Correct 10 ms 17792 KB Output is correct
39 Correct 10 ms 17792 KB Output is correct
40 Correct 9 ms 17152 KB Output is correct
41 Correct 10 ms 17792 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Execution timed out 501 ms 764804 KB Time limit exceeded
44 Halted 0 ms 0 KB -