답안 #316767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316767 2020-10-28T00:06:40 Z aZvezda Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
95 ms 163068 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define out(x) "{" << (#x) << ": " << x << "} "

const int MAX_N = 410;
int dp[MAX_N][MAX_N][MAX_N][3];
int n;
string in;
int cnt[MAX_N][3];
vector<int> ind[3];

int getCode(char c) {
	if(c == 'R') {
		return 0;
	} else if(c == 'G') {
		return 1;
	} else if(c == 'Y') {
		return 2;
	}
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	cin >> in;

	for(int i = 0; i < n; i ++) {
		if(i != 0) {
			for(int j = 0; j < 3; j ++) {
				cnt[i][j] = cnt[i - 1][j];
			}
		}
		cnt[i][getCode(in[i])] ++;
		ind[getCode(in[i])].push_back(i);
	}

	for(int i = 0; i <= ind[0].size(); i ++) {
		for(int j = 0; j <= ind[1].size(); j ++) {
			for(int k = 0; k <= ind[2].size(); k ++) {
				for(int last = 0; last < 3; last ++) {
					dp[i][j][k][last] = mod;
				}
			}
		}
	}
	
	dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;

	for(int i = 0; i <= ind[0].size(); i ++) {
		for(int j = 0; j <= ind[1].size(); j ++) {
			for(int k = 0; k <= ind[2].size(); k ++) {
				for(int last = 0; last < 3; last ++) {
					if(dp[i][j][k][last] == mod) {continue;}
					if(last != 0 && i != ind[0].size()) {
						int toGet = ind[0][i];
						int cost = max(0, cnt[toGet][1] - j) + max(0, cnt[toGet][2] - k);
						chkmin(dp[i + 1][j][k][0], dp[i][j][k][last] + cost);
					} 
					if(last != 1 && j != ind[1].size()) {
						int toGet = ind[1][j];
						int cost = max(0, cnt[toGet][0] - i) + max(0, cnt[toGet][2] - k);
						chkmin(dp[i][j + 1][k][1], dp[i][j][k][last] + cost);
					} 	
					if(last != 2 && k != ind[2].size()) {
						int toGet = ind[2][k];
						int cost = max(0, cnt[toGet][0] - i) + max(0, cnt[toGet][1] - j);
						chkmin(dp[i][j][k + 1][2], dp[i][j][k][last] + cost);
					} 
				}
			}
		}
	}
	
	int ans = mod;
	for(int i = 0; i < 3; i ++) {
		chkmin(ans, dp[ind[0].size()][ind[1].size()][ind[2].size()][i]);
	}
	
	if(ans >= mod) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int i = 0; i <= ind[0].size(); i ++) {
      |                 ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int j = 0; j <= ind[1].size(); j ++) {
      |                  ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int k = 0; k <= ind[2].size(); k ++) {
      |                   ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i = 0; i <= ind[0].size(); i ++) {
      |                 ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int j = 0; j <= ind[1].size(); j ++) {
      |                  ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    for(int k = 0; k <= ind[2].size(); k ++) {
      |                   ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:63:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |      if(last != 0 && i != ind[0].size()) {
      |                      ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:68:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |      if(last != 1 && j != ind[1].size()) {
      |                      ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:73:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |      if(last != 2 && k != ind[2].size()) {
      |                      ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int getCode(char)':
joi2019_ho_t3.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
   29 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 2304 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 2 ms 2304 KB Output is correct
21 Correct 2 ms 2432 KB Output is correct
22 Correct 1 ms 1664 KB Output is correct
23 Correct 2 ms 2176 KB Output is correct
24 Correct 1 ms 1664 KB Output is correct
25 Correct 2 ms 3968 KB Output is correct
26 Correct 2 ms 4224 KB Output is correct
27 Correct 2 ms 3072 KB Output is correct
28 Correct 2 ms 2432 KB Output is correct
29 Correct 1 ms 2304 KB Output is correct
30 Correct 2 ms 2304 KB Output is correct
31 Correct 2 ms 2048 KB Output is correct
32 Correct 2 ms 2432 KB Output is correct
33 Correct 2 ms 3840 KB Output is correct
34 Correct 2 ms 3616 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 1 ms 1920 KB Output is correct
37 Correct 1 ms 1792 KB Output is correct
38 Correct 2 ms 2176 KB Output is correct
39 Correct 2 ms 2304 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 1 ms 2304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 84 ms 163064 KB Output is correct
3 Correct 83 ms 162168 KB Output is correct
4 Correct 84 ms 163064 KB Output is correct
5 Correct 84 ms 163064 KB Output is correct
6 Correct 86 ms 163064 KB Output is correct
7 Correct 91 ms 162296 KB Output is correct
8 Correct 83 ms 162168 KB Output is correct
9 Correct 85 ms 161400 KB Output is correct
10 Correct 85 ms 162980 KB Output is correct
11 Correct 86 ms 163068 KB Output is correct
12 Correct 23 ms 44160 KB Output is correct
13 Correct 40 ms 77176 KB Output is correct
14 Correct 59 ms 111424 KB Output is correct
15 Correct 85 ms 163064 KB Output is correct
16 Correct 84 ms 163064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 2304 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 2 ms 2304 KB Output is correct
21 Correct 2 ms 2432 KB Output is correct
22 Correct 1 ms 1664 KB Output is correct
23 Correct 2 ms 2176 KB Output is correct
24 Correct 1 ms 1664 KB Output is correct
25 Correct 2 ms 3968 KB Output is correct
26 Correct 2 ms 4224 KB Output is correct
27 Correct 2 ms 3072 KB Output is correct
28 Correct 2 ms 2432 KB Output is correct
29 Correct 1 ms 2304 KB Output is correct
30 Correct 2 ms 2304 KB Output is correct
31 Correct 2 ms 2048 KB Output is correct
32 Correct 2 ms 2432 KB Output is correct
33 Correct 2 ms 3840 KB Output is correct
34 Correct 2 ms 3616 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 1 ms 1920 KB Output is correct
37 Correct 1 ms 1792 KB Output is correct
38 Correct 2 ms 2176 KB Output is correct
39 Correct 2 ms 2304 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 1 ms 2304 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 84 ms 163064 KB Output is correct
44 Correct 83 ms 162168 KB Output is correct
45 Correct 84 ms 163064 KB Output is correct
46 Correct 84 ms 163064 KB Output is correct
47 Correct 86 ms 163064 KB Output is correct
48 Correct 91 ms 162296 KB Output is correct
49 Correct 83 ms 162168 KB Output is correct
50 Correct 85 ms 161400 KB Output is correct
51 Correct 85 ms 162980 KB Output is correct
52 Correct 86 ms 163068 KB Output is correct
53 Correct 23 ms 44160 KB Output is correct
54 Correct 40 ms 77176 KB Output is correct
55 Correct 59 ms 111424 KB Output is correct
56 Correct 85 ms 163064 KB Output is correct
57 Correct 84 ms 163064 KB Output is correct
58 Correct 75 ms 77184 KB Output is correct
59 Correct 88 ms 97912 KB Output is correct
60 Correct 81 ms 88956 KB Output is correct
61 Correct 80 ms 85888 KB Output is correct
62 Correct 87 ms 160632 KB Output is correct
63 Correct 89 ms 160248 KB Output is correct
64 Correct 92 ms 150136 KB Output is correct
65 Correct 95 ms 138488 KB Output is correct
66 Correct 82 ms 87160 KB Output is correct
67 Correct 79 ms 83964 KB Output is correct
68 Correct 83 ms 89976 KB Output is correct
69 Correct 82 ms 86528 KB Output is correct
70 Correct 83 ms 93796 KB Output is correct
71 Correct 77 ms 84984 KB Output is correct
72 Correct 28 ms 42112 KB Output is correct
73 Correct 3 ms 2944 KB Output is correct