Submission #478578

# Submission time Handle Problem Language Result Execution time Memory
478578 2021-10-08T02:51:56 Z MonkeyKing Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
60 / 100
42 ms 37108 KB
#include <numeric>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#include <time.h>
#define Endl endl
#define mp make_pair
#define mt make_tuple
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1000000007;
const int gmod=3;
const int inf=1039074182;
const double eps=1e-9;
const double pi=3.141592653589793238462643383279;
const ll llinf=2LL*inf*inf;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
inline void chadd(int &x,int b) {x+=b-mod;x+=(x>>31 & mod);}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;}
template <typename T1,typename T2> inline void chmul(T1 &x,T2 b) {x=1LL*x*b%mod;}
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
template <typename T> inline T mabs(T x) {return (x<0?-x:x);}
using namespace std;
int n;
int a[405];
int cnt[3][405];
char c[405];
int dp[105][105][105][4];
int pre[3][405][3];//某个球的第几个,上一个那个type的球是第几个。
int t[3];

inline int calc(int tot,int a,int b,int c,int k)
{
	t[0]=a;t[1]=b;t[2]=c;
	for(int i=0;i<3;i++) if(t[i]+(k==i)>cnt[i][n-1]) return inf;
	int cost=0;
	for(int i=0;i<3;i++)
	{
		cost+=max(0,t[i]-pre[k][t[k]+1][i]-(k==i));
	}
	return cost;
}

int main()
{
	// freopen("input.txt","r",stdin);
	cin>>n;
	scanf("%s",c);
	for(int i=0;i<n;i++) a[i]=(c[i]=='R'?0:(c[i]=='G'?1:2));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cnt[j][i]=(i?cnt[j][i-1]:0);
			if(a[i]==j) cnt[j][i]++;
		}
		for(int j=0;j<3;j++)
		{
			pre[a[i]][cnt[a[i]][i]][j]=t[j];
		}
		t[a[i]]=cnt[a[i]][i];
	}
	// for(int i=0;i<n;i++) cout<<a[i]<<' ';
	// cout<<endl;
	memset(dp,0x3f,sizeof(dp));
	// cout<<calc(1,1,0,0,1)<<endl;
	// return 0;
	dp[0][0][0][3]=0;
	for(int i=0;i<=n;i++)
	{
		for(int a=0;a<=i;a++)
		{
			for(int b=0;b<=i-a;b++)
			{
				int c=i-a-b;
				for(int lst=0;lst<=3;lst++)
				{
					for(int nlst=0;nlst<3;nlst++)
					{
						if(nlst==lst) continue;
						if(nlst==0) chmin(dp[i+1][a+1][b][nlst],dp[i][a][b][lst]+calc(i,a,b,c,0));
						if(nlst==1) chmin(dp[i+1][a][b+1][nlst],dp[i][a][b][lst]+calc(i,a,b,c,1));
						if(nlst==2) chmin(dp[i+1][a][b][nlst],dp[i][a][b][lst]+calc(i,a,b,c,2));
					}
				}
			}
		}
	}
	// cout<<dp[1][1][0][0]<<endl;
	// cout<<dp[2][1][1][1]<<endl;
	int res=inf;
	for(int lst=0;lst<3;lst++)
	{
		chmin(res,dp[n][cnt[0][n-1]][cnt[1][n-1]][lst]);
	}
	cout<<(res>=inf?-1:res)<<endl;
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |  scanf("%s",c);
      |  ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 18380 KB Output is correct
2 Correct 8 ms 18380 KB Output is correct
3 Correct 9 ms 18380 KB Output is correct
4 Correct 10 ms 18380 KB Output is correct
5 Correct 9 ms 18380 KB Output is correct
6 Correct 10 ms 18380 KB Output is correct
7 Correct 9 ms 18380 KB Output is correct
8 Correct 10 ms 18380 KB Output is correct
9 Correct 9 ms 18380 KB Output is correct
10 Correct 10 ms 18368 KB Output is correct
11 Correct 8 ms 18380 KB Output is correct
12 Correct 8 ms 18380 KB Output is correct
13 Correct 9 ms 18380 KB Output is correct
14 Correct 10 ms 18332 KB Output is correct
15 Correct 9 ms 18424 KB Output is correct
16 Correct 9 ms 18380 KB Output is correct
17 Correct 9 ms 18376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 18380 KB Output is correct
2 Correct 8 ms 18380 KB Output is correct
3 Correct 9 ms 18380 KB Output is correct
4 Correct 10 ms 18380 KB Output is correct
5 Correct 9 ms 18380 KB Output is correct
6 Correct 10 ms 18380 KB Output is correct
7 Correct 9 ms 18380 KB Output is correct
8 Correct 10 ms 18380 KB Output is correct
9 Correct 9 ms 18380 KB Output is correct
10 Correct 10 ms 18368 KB Output is correct
11 Correct 8 ms 18380 KB Output is correct
12 Correct 8 ms 18380 KB Output is correct
13 Correct 9 ms 18380 KB Output is correct
14 Correct 10 ms 18332 KB Output is correct
15 Correct 9 ms 18424 KB Output is correct
16 Correct 9 ms 18380 KB Output is correct
17 Correct 9 ms 18376 KB Output is correct
18 Correct 11 ms 18396 KB Output is correct
19 Correct 11 ms 18380 KB Output is correct
20 Correct 11 ms 18380 KB Output is correct
21 Correct 12 ms 18432 KB Output is correct
22 Correct 12 ms 18380 KB Output is correct
23 Correct 13 ms 18436 KB Output is correct
24 Correct 12 ms 18380 KB Output is correct
25 Correct 14 ms 18380 KB Output is correct
26 Correct 12 ms 18380 KB Output is correct
27 Correct 13 ms 18508 KB Output is correct
28 Correct 12 ms 18380 KB Output is correct
29 Correct 11 ms 18380 KB Output is correct
30 Correct 11 ms 18424 KB Output is correct
31 Correct 12 ms 18380 KB Output is correct
32 Correct 11 ms 18380 KB Output is correct
33 Correct 11 ms 18380 KB Output is correct
34 Correct 12 ms 18432 KB Output is correct
35 Correct 12 ms 18380 KB Output is correct
36 Correct 12 ms 18380 KB Output is correct
37 Correct 10 ms 18412 KB Output is correct
38 Correct 12 ms 18352 KB Output is correct
39 Correct 11 ms 18380 KB Output is correct
40 Correct 11 ms 18380 KB Output is correct
41 Correct 11 ms 18436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 18380 KB Output is correct
2 Runtime error 42 ms 37108 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 18380 KB Output is correct
2 Correct 8 ms 18380 KB Output is correct
3 Correct 9 ms 18380 KB Output is correct
4 Correct 10 ms 18380 KB Output is correct
5 Correct 9 ms 18380 KB Output is correct
6 Correct 10 ms 18380 KB Output is correct
7 Correct 9 ms 18380 KB Output is correct
8 Correct 10 ms 18380 KB Output is correct
9 Correct 9 ms 18380 KB Output is correct
10 Correct 10 ms 18368 KB Output is correct
11 Correct 8 ms 18380 KB Output is correct
12 Correct 8 ms 18380 KB Output is correct
13 Correct 9 ms 18380 KB Output is correct
14 Correct 10 ms 18332 KB Output is correct
15 Correct 9 ms 18424 KB Output is correct
16 Correct 9 ms 18380 KB Output is correct
17 Correct 9 ms 18376 KB Output is correct
18 Correct 11 ms 18396 KB Output is correct
19 Correct 11 ms 18380 KB Output is correct
20 Correct 11 ms 18380 KB Output is correct
21 Correct 12 ms 18432 KB Output is correct
22 Correct 12 ms 18380 KB Output is correct
23 Correct 13 ms 18436 KB Output is correct
24 Correct 12 ms 18380 KB Output is correct
25 Correct 14 ms 18380 KB Output is correct
26 Correct 12 ms 18380 KB Output is correct
27 Correct 13 ms 18508 KB Output is correct
28 Correct 12 ms 18380 KB Output is correct
29 Correct 11 ms 18380 KB Output is correct
30 Correct 11 ms 18424 KB Output is correct
31 Correct 12 ms 18380 KB Output is correct
32 Correct 11 ms 18380 KB Output is correct
33 Correct 11 ms 18380 KB Output is correct
34 Correct 12 ms 18432 KB Output is correct
35 Correct 12 ms 18380 KB Output is correct
36 Correct 12 ms 18380 KB Output is correct
37 Correct 10 ms 18412 KB Output is correct
38 Correct 12 ms 18352 KB Output is correct
39 Correct 11 ms 18380 KB Output is correct
40 Correct 11 ms 18380 KB Output is correct
41 Correct 11 ms 18436 KB Output is correct
42 Correct 9 ms 18380 KB Output is correct
43 Runtime error 42 ms 37108 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -