답안 #263548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263548 2020-08-13T19:22:34 Z sahil_k Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
75 / 100
500 ms 384632 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<=i; j++) {
			for (int k=0; k<=i; 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; j++) {
			for (int k=0; k<=i; 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;
      |                                                              ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
5 Correct 1 ms 896 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 896 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 1 ms 896 KB Output is correct
11 Correct 1 ms 896 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 896 KB Output is correct
15 Correct 1 ms 896 KB Output is correct
16 Correct 1 ms 896 KB Output is correct
17 Correct 1 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
5 Correct 1 ms 896 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 896 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 1 ms 896 KB Output is correct
11 Correct 1 ms 896 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 896 KB Output is correct
15 Correct 1 ms 896 KB Output is correct
16 Correct 1 ms 896 KB Output is correct
17 Correct 1 ms 896 KB Output is correct
18 Correct 6 ms 8960 KB Output is correct
19 Correct 6 ms 9088 KB Output is correct
20 Correct 7 ms 9088 KB Output is correct
21 Correct 6 ms 9088 KB Output is correct
22 Correct 6 ms 9088 KB Output is correct
23 Correct 6 ms 8960 KB Output is correct
24 Correct 6 ms 9088 KB Output is correct
25 Correct 5 ms 9088 KB Output is correct
26 Correct 5 ms 9088 KB Output is correct
27 Correct 6 ms 9088 KB Output is correct
28 Correct 5 ms 9088 KB Output is correct
29 Correct 5 ms 9088 KB Output is correct
30 Correct 6 ms 9088 KB Output is correct
31 Correct 6 ms 9088 KB Output is correct
32 Correct 6 ms 9088 KB Output is correct
33 Correct 5 ms 8704 KB Output is correct
34 Correct 6 ms 8704 KB Output is correct
35 Correct 7 ms 8448 KB Output is correct
36 Correct 5 ms 8704 KB Output is correct
37 Correct 5 ms 8168 KB Output is correct
38 Correct 6 ms 8960 KB Output is correct
39 Correct 6 ms 9088 KB Output is correct
40 Correct 5 ms 8704 KB Output is correct
41 Correct 5 ms 9088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 259 ms 384504 KB Output is correct
3 Correct 288 ms 382584 KB Output is correct
4 Correct 266 ms 384504 KB Output is correct
5 Correct 259 ms 384632 KB Output is correct
6 Correct 258 ms 384568 KB Output is correct
7 Correct 272 ms 382584 KB Output is correct
8 Correct 268 ms 382584 KB Output is correct
9 Correct 256 ms 380700 KB Output is correct
10 Correct 276 ms 384632 KB Output is correct
11 Correct 258 ms 384580 KB Output is correct
12 Correct 70 ms 102904 KB Output is correct
13 Correct 115 ms 181368 KB Output is correct
14 Correct 183 ms 262392 KB Output is correct
15 Correct 258 ms 384504 KB Output is correct
16 Correct 271 ms 384504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
5 Correct 1 ms 896 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 896 KB Output is correct
9 Correct 1 ms 896 KB Output is correct
10 Correct 1 ms 896 KB Output is correct
11 Correct 1 ms 896 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 896 KB Output is correct
15 Correct 1 ms 896 KB Output is correct
16 Correct 1 ms 896 KB Output is correct
17 Correct 1 ms 896 KB Output is correct
18 Correct 6 ms 8960 KB Output is correct
19 Correct 6 ms 9088 KB Output is correct
20 Correct 7 ms 9088 KB Output is correct
21 Correct 6 ms 9088 KB Output is correct
22 Correct 6 ms 9088 KB Output is correct
23 Correct 6 ms 8960 KB Output is correct
24 Correct 6 ms 9088 KB Output is correct
25 Correct 5 ms 9088 KB Output is correct
26 Correct 5 ms 9088 KB Output is correct
27 Correct 6 ms 9088 KB Output is correct
28 Correct 5 ms 9088 KB Output is correct
29 Correct 5 ms 9088 KB Output is correct
30 Correct 6 ms 9088 KB Output is correct
31 Correct 6 ms 9088 KB Output is correct
32 Correct 6 ms 9088 KB Output is correct
33 Correct 5 ms 8704 KB Output is correct
34 Correct 6 ms 8704 KB Output is correct
35 Correct 7 ms 8448 KB Output is correct
36 Correct 5 ms 8704 KB Output is correct
37 Correct 5 ms 8168 KB Output is correct
38 Correct 6 ms 8960 KB Output is correct
39 Correct 6 ms 9088 KB Output is correct
40 Correct 5 ms 8704 KB Output is correct
41 Correct 5 ms 9088 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 259 ms 384504 KB Output is correct
44 Correct 288 ms 382584 KB Output is correct
45 Correct 266 ms 384504 KB Output is correct
46 Correct 259 ms 384632 KB Output is correct
47 Correct 258 ms 384568 KB Output is correct
48 Correct 272 ms 382584 KB Output is correct
49 Correct 268 ms 382584 KB Output is correct
50 Correct 256 ms 380700 KB Output is correct
51 Correct 276 ms 384632 KB Output is correct
52 Correct 258 ms 384580 KB Output is correct
53 Correct 70 ms 102904 KB Output is correct
54 Correct 115 ms 181368 KB Output is correct
55 Correct 183 ms 262392 KB Output is correct
56 Correct 258 ms 384504 KB Output is correct
57 Correct 271 ms 384504 KB Output is correct
58 Execution timed out 570 ms 384504 KB Time limit exceeded
59 Halted 0 ms 0 KB -