답안 #217372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217372 2020-03-29T13:30:46 Z kshitij_sodani Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
444 ms 755704 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl "\n"
llo mod=1000000007;
int n;
int it[401];
int dp[401][401][401][3];
vector<int> aa;
vector<int> bb;
vector<int> cc;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	char ss;
	int co=0;
	int co2=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;k<=n;k++){
				for(int l=0;l<3;l++){
					dp[i][j][k][l]=400000;
				}
			}
		}
	}
	int pre[n][3];
	for(int i=0;i<n;i++){
		if(i==0){
			pre[i][0]=0;
			pre[i][1]=0;
			pre[i][2]=0;
		}
		else{
			pre[i][0]=pre[i-1][0];
			pre[i][1]=pre[i-1][1];
			pre[i][2]=pre[i-1][2];
		}
		cin>>ss;
		if(ss=='R'){
			co+=1;
			aa.pb(i);
			pre[i][0]+=1;
		}
		else if(ss=='G'){
			it[i]=1;
			co2+=1;
			pre[i][1]+=1;
			bb.pb(i);
		}
		else{
			pre[i][2]+=1;
			cc.pb(i);
		}
	}
	if(co>(n+1)/2 or co2>(n+1)/2 or (n-co-co2)>(n+1)/2){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=min((int)aa.size(),i+1);j++){
			for(int k=0;k<=min((int)bb.size(),i+1-j);k++){
				if((i+1)-j-k>(i+2)/2 or j>(i+2)/2 or k>(i+2)/2 or j+k>i+1 or j>aa.size() or k>bb.size() or i+1-j-k>cc.size()){
					continue;
				}
			//	cout<<i+1<<" "<<j<<" "<<k<<endl;
				if(j>0){
					int co=0;
					if(k>0){
						co+=max(pre[bb[k-1]][1]-pre[aa[j-1]][1],0);
					}
					if(i+1-j-k>0){
						co+=max(pre[cc[i-j-k]][2]-pre[aa[j-1]][2],0);
					}
					if(i>0){
						dp[i][j][k][0]=co+min(dp[i-1][j-1][k][1],dp[i-1][j-1][k][2]);
					}
					else{
						dp[i][j][k][0]=co;
					}
				}
				if(k>0){
					int co=0;
					if(j>0){
						co+=max(pre[aa[j-1]][0]-pre[bb[k-1]][0],0);
					}
					if(i+1-j-k>0){
						co+=max(pre[cc[i-j-k]][2]-pre[bb[k-1]][2],0);
					}
					if(i>0){
						dp[i][j][k][1]=co+min(dp[i-1][j][k-1][0],dp[i-1][j][k-1][2]);
					}
					else{
						dp[i][j][k][1]=co;
					}
				}
				if(j+k<i+1){
					int co=0;
					if(k>0){
						co+=max(pre[bb[k-1]][1]-pre[cc[i-j-k]][1],0);
					}
					if(j>0){
						co+=max(pre[aa[j-1]][0]-pre[cc[i-j-k]][0],0);
					}
					if(i>0){
						dp[i][j][k][2]=co+min(dp[i-1][j][k][0],dp[i-1][j][k][1]);
					}
					else{
						dp[i][j][k][2]=co;
					}
				}


			}
		}
	}
	int mi=400000;
	for(int j=0;j<=3;j++){
			mi=min(mi,dp[n-1][aa.size()][bb.size()][j]);
	}

	cout<<mi<<endl;
 
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:68:67: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if((i+1)-j-k>(i+2)/2 or j>(i+2)/2 or k>(i+2)/2 or j+k>i+1 or j>aa.size() or k>bb.size() or i+1-j-k>cc.size()){
                                                                  ~^~~~~~~~~~
joi2019_ho_t3.cpp:68:82: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if((i+1)-j-k>(i+2)/2 or j>(i+2)/2 or k>(i+2)/2 or j+k>i+1 or j>aa.size() or k>bb.size() or i+1-j-k>cc.size()){
                                                                                 ~^~~~~~~~~~
joi2019_ho_t3.cpp:68:103: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if((i+1)-j-k>(i+2)/2 or j>(i+2)/2 or k>(i+2)/2 or j+k>i+1 or j>aa.size() or k>bb.size() or i+1-j-k>cc.size()){
                                                                                                ~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 5 ms 1408 KB Output is correct
7 Correct 5 ms 1408 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 1408 KB Output is correct
10 Correct 5 ms 1408 KB Output is correct
11 Correct 5 ms 1408 KB Output is correct
12 Correct 5 ms 1408 KB Output is correct
13 Correct 5 ms 1408 KB Output is correct
14 Correct 5 ms 1280 KB Output is correct
15 Correct 5 ms 1408 KB Output is correct
16 Correct 5 ms 1408 KB Output is correct
17 Correct 5 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 5 ms 1408 KB Output is correct
7 Correct 5 ms 1408 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 1408 KB Output is correct
10 Correct 5 ms 1408 KB Output is correct
11 Correct 5 ms 1408 KB Output is correct
12 Correct 5 ms 1408 KB Output is correct
13 Correct 5 ms 1408 KB Output is correct
14 Correct 5 ms 1280 KB Output is correct
15 Correct 5 ms 1408 KB Output is correct
16 Correct 5 ms 1408 KB Output is correct
17 Correct 5 ms 1280 KB Output is correct
18 Correct 13 ms 17792 KB Output is correct
19 Correct 13 ms 17792 KB Output is correct
20 Correct 13 ms 17792 KB Output is correct
21 Correct 13 ms 17792 KB Output is correct
22 Correct 13 ms 17792 KB Output is correct
23 Correct 13 ms 17792 KB Output is correct
24 Correct 12 ms 17792 KB Output is correct
25 Correct 13 ms 17792 KB Output is correct
26 Correct 12 ms 17792 KB Output is correct
27 Correct 14 ms 17792 KB Output is correct
28 Correct 13 ms 17792 KB Output is correct
29 Correct 13 ms 17792 KB Output is correct
30 Correct 12 ms 17792 KB Output is correct
31 Correct 13 ms 17792 KB Output is correct
32 Correct 13 ms 17792 KB Output is correct
33 Correct 12 ms 17152 KB Output is correct
34 Correct 12 ms 17152 KB Output is correct
35 Correct 12 ms 16640 KB Output is correct
36 Correct 12 ms 17152 KB Output is correct
37 Correct 12 ms 16000 KB Output is correct
38 Correct 12 ms 17792 KB Output is correct
39 Correct 13 ms 17792 KB Output is correct
40 Correct 12 ms 17152 KB Output is correct
41 Correct 13 ms 17792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 403 ms 755576 KB Output is correct
3 Correct 404 ms 753528 KB Output is correct
4 Correct 415 ms 755576 KB Output is correct
5 Correct 406 ms 755704 KB Output is correct
6 Correct 395 ms 755576 KB Output is correct
7 Correct 402 ms 753528 KB Output is correct
8 Correct 402 ms 753400 KB Output is correct
9 Correct 402 ms 749816 KB Output is correct
10 Correct 402 ms 755576 KB Output is correct
11 Correct 403 ms 755568 KB Output is correct
12 Correct 106 ms 201848 KB Output is correct
13 Correct 185 ms 356088 KB Output is correct
14 Correct 278 ms 515964 KB Output is correct
15 Correct 384 ms 755576 KB Output is correct
16 Correct 395 ms 755704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 5 ms 1408 KB Output is correct
7 Correct 5 ms 1408 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 1408 KB Output is correct
10 Correct 5 ms 1408 KB Output is correct
11 Correct 5 ms 1408 KB Output is correct
12 Correct 5 ms 1408 KB Output is correct
13 Correct 5 ms 1408 KB Output is correct
14 Correct 5 ms 1280 KB Output is correct
15 Correct 5 ms 1408 KB Output is correct
16 Correct 5 ms 1408 KB Output is correct
17 Correct 5 ms 1280 KB Output is correct
18 Correct 13 ms 17792 KB Output is correct
19 Correct 13 ms 17792 KB Output is correct
20 Correct 13 ms 17792 KB Output is correct
21 Correct 13 ms 17792 KB Output is correct
22 Correct 13 ms 17792 KB Output is correct
23 Correct 13 ms 17792 KB Output is correct
24 Correct 12 ms 17792 KB Output is correct
25 Correct 13 ms 17792 KB Output is correct
26 Correct 12 ms 17792 KB Output is correct
27 Correct 14 ms 17792 KB Output is correct
28 Correct 13 ms 17792 KB Output is correct
29 Correct 13 ms 17792 KB Output is correct
30 Correct 12 ms 17792 KB Output is correct
31 Correct 13 ms 17792 KB Output is correct
32 Correct 13 ms 17792 KB Output is correct
33 Correct 12 ms 17152 KB Output is correct
34 Correct 12 ms 17152 KB Output is correct
35 Correct 12 ms 16640 KB Output is correct
36 Correct 12 ms 17152 KB Output is correct
37 Correct 12 ms 16000 KB Output is correct
38 Correct 12 ms 17792 KB Output is correct
39 Correct 13 ms 17792 KB Output is correct
40 Correct 12 ms 17152 KB Output is correct
41 Correct 13 ms 17792 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 403 ms 755576 KB Output is correct
44 Correct 404 ms 753528 KB Output is correct
45 Correct 415 ms 755576 KB Output is correct
46 Correct 406 ms 755704 KB Output is correct
47 Correct 395 ms 755576 KB Output is correct
48 Correct 402 ms 753528 KB Output is correct
49 Correct 402 ms 753400 KB Output is correct
50 Correct 402 ms 749816 KB Output is correct
51 Correct 402 ms 755576 KB Output is correct
52 Correct 403 ms 755568 KB Output is correct
53 Correct 106 ms 201848 KB Output is correct
54 Correct 185 ms 356088 KB Output is correct
55 Correct 278 ms 515964 KB Output is correct
56 Correct 384 ms 755576 KB Output is correct
57 Correct 395 ms 755704 KB Output is correct
58 Correct 420 ms 755576 KB Output is correct
59 Correct 425 ms 755704 KB Output is correct
60 Correct 410 ms 749560 KB Output is correct
61 Correct 425 ms 753656 KB Output is correct
62 Correct 388 ms 755576 KB Output is correct
63 Correct 410 ms 755704 KB Output is correct
64 Correct 402 ms 755576 KB Output is correct
65 Correct 414 ms 753528 KB Output is correct
66 Correct 412 ms 745848 KB Output is correct
67 Correct 418 ms 755672 KB Output is correct
68 Correct 413 ms 753404 KB Output is correct
69 Correct 444 ms 755580 KB Output is correct
70 Correct 424 ms 755576 KB Output is correct
71 Correct 425 ms 753400 KB Output is correct
72 Correct 387 ms 753400 KB Output is correct
73 Correct 381 ms 755576 KB Output is correct