Submission #316766

# Submission time Handle Problem Language Result Execution time Memory
316766 2020-10-28T00:05:06 Z aZvezda Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
60 / 100
498 ms 809848 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);
	for(int i = 0; i < MAX_N; i ++) {
		for(int j = 0; j < MAX_N; j ++) {
			for(int k = 0; k < MAX_N; k ++) {
				for(int q = 0; q < 3; q ++) {
					dp[i][j][k][q] = mod;
				}
			}
		}
	} 
	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);
	}
	
	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 > MAX_N) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for(int i = 0; i <= ind[0].size(); i ++) {
      |                 ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int j = 0; j <= ind[1].size(); j ++) {
      |                  ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    for(int k = 0; k <= ind[2].size(); k ++) {
      |                   ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:61:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |      if(last != 0 && i != ind[0].size()) {
      |                      ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:66:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |      if(last != 1 && j != ind[1].size()) {
      |                      ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:71:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |      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 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 489 ms 809592 KB Output is correct
2 Correct 492 ms 809588 KB Output is correct
3 Correct 487 ms 809720 KB Output is correct
4 Correct 487 ms 809592 KB Output is correct
5 Correct 491 ms 809592 KB Output is correct
6 Correct 491 ms 809720 KB Output is correct
7 Correct 488 ms 809740 KB Output is correct
8 Correct 492 ms 809720 KB Output is correct
9 Correct 490 ms 809720 KB Output is correct
10 Correct 489 ms 809720 KB Output is correct
11 Correct 491 ms 809592 KB Output is correct
12 Correct 489 ms 809532 KB Output is correct
13 Correct 490 ms 809592 KB Output is correct
14 Correct 489 ms 809592 KB Output is correct
15 Correct 489 ms 809592 KB Output is correct
16 Correct 492 ms 809720 KB Output is correct
17 Correct 489 ms 809592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 489 ms 809592 KB Output is correct
2 Correct 492 ms 809588 KB Output is correct
3 Correct 487 ms 809720 KB Output is correct
4 Correct 487 ms 809592 KB Output is correct
5 Correct 491 ms 809592 KB Output is correct
6 Correct 491 ms 809720 KB Output is correct
7 Correct 488 ms 809740 KB Output is correct
8 Correct 492 ms 809720 KB Output is correct
9 Correct 490 ms 809720 KB Output is correct
10 Correct 489 ms 809720 KB Output is correct
11 Correct 491 ms 809592 KB Output is correct
12 Correct 489 ms 809532 KB Output is correct
13 Correct 490 ms 809592 KB Output is correct
14 Correct 489 ms 809592 KB Output is correct
15 Correct 489 ms 809592 KB Output is correct
16 Correct 492 ms 809720 KB Output is correct
17 Correct 489 ms 809592 KB Output is correct
18 Correct 486 ms 809648 KB Output is correct
19 Correct 484 ms 809720 KB Output is correct
20 Correct 493 ms 809696 KB Output is correct
21 Correct 494 ms 809592 KB Output is correct
22 Correct 489 ms 809592 KB Output is correct
23 Correct 489 ms 809592 KB Output is correct
24 Correct 492 ms 809720 KB Output is correct
25 Correct 487 ms 809592 KB Output is correct
26 Correct 489 ms 809528 KB Output is correct
27 Correct 488 ms 809720 KB Output is correct
28 Correct 488 ms 809512 KB Output is correct
29 Correct 496 ms 809720 KB Output is correct
30 Correct 494 ms 809592 KB Output is correct
31 Correct 489 ms 809720 KB Output is correct
32 Correct 491 ms 809720 KB Output is correct
33 Correct 491 ms 809592 KB Output is correct
34 Correct 490 ms 809720 KB Output is correct
35 Correct 492 ms 809544 KB Output is correct
36 Correct 489 ms 809596 KB Output is correct
37 Correct 486 ms 809592 KB Output is correct
38 Correct 489 ms 809720 KB Output is correct
39 Correct 491 ms 809576 KB Output is correct
40 Correct 498 ms 809720 KB Output is correct
41 Correct 491 ms 809592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 496 ms 809848 KB Output is correct
2 Incorrect 495 ms 809592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 489 ms 809592 KB Output is correct
2 Correct 492 ms 809588 KB Output is correct
3 Correct 487 ms 809720 KB Output is correct
4 Correct 487 ms 809592 KB Output is correct
5 Correct 491 ms 809592 KB Output is correct
6 Correct 491 ms 809720 KB Output is correct
7 Correct 488 ms 809740 KB Output is correct
8 Correct 492 ms 809720 KB Output is correct
9 Correct 490 ms 809720 KB Output is correct
10 Correct 489 ms 809720 KB Output is correct
11 Correct 491 ms 809592 KB Output is correct
12 Correct 489 ms 809532 KB Output is correct
13 Correct 490 ms 809592 KB Output is correct
14 Correct 489 ms 809592 KB Output is correct
15 Correct 489 ms 809592 KB Output is correct
16 Correct 492 ms 809720 KB Output is correct
17 Correct 489 ms 809592 KB Output is correct
18 Correct 486 ms 809648 KB Output is correct
19 Correct 484 ms 809720 KB Output is correct
20 Correct 493 ms 809696 KB Output is correct
21 Correct 494 ms 809592 KB Output is correct
22 Correct 489 ms 809592 KB Output is correct
23 Correct 489 ms 809592 KB Output is correct
24 Correct 492 ms 809720 KB Output is correct
25 Correct 487 ms 809592 KB Output is correct
26 Correct 489 ms 809528 KB Output is correct
27 Correct 488 ms 809720 KB Output is correct
28 Correct 488 ms 809512 KB Output is correct
29 Correct 496 ms 809720 KB Output is correct
30 Correct 494 ms 809592 KB Output is correct
31 Correct 489 ms 809720 KB Output is correct
32 Correct 491 ms 809720 KB Output is correct
33 Correct 491 ms 809592 KB Output is correct
34 Correct 490 ms 809720 KB Output is correct
35 Correct 492 ms 809544 KB Output is correct
36 Correct 489 ms 809596 KB Output is correct
37 Correct 486 ms 809592 KB Output is correct
38 Correct 489 ms 809720 KB Output is correct
39 Correct 491 ms 809576 KB Output is correct
40 Correct 498 ms 809720 KB Output is correct
41 Correct 491 ms 809592 KB Output is correct
42 Correct 496 ms 809848 KB Output is correct
43 Incorrect 495 ms 809592 KB Output isn't correct
44 Halted 0 ms 0 KB -