답안 #478579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478579 2021-10-08T02:52:52 Z MonkeyKing Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
60 / 100
500 ms 5564 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[2][405][405][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;
	// return 0;
	dp[0][0][0][3]=0;
	for(int i=0;i<=n;i++)
	{
		int cur=i&1,nxt=cur^1;
		memset(dp[nxt],0x3f,sizeof(dp[nxt]));
		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[nxt][a+1][b][nlst],dp[cur][a][b][lst]+calc(cur,a,b,c,0));
						if(nlst==1) chmin(dp[nxt][a][b+1][nlst],dp[cur][a][b][lst]+calc(i,a,b,c,1));
						if(nlst==2) chmin(dp[nxt][a][b][nlst],dp[cur][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&1][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);
      |  ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5324 KB Output is correct
2 Correct 3 ms 5324 KB Output is correct
3 Correct 4 ms 5324 KB Output is correct
4 Correct 4 ms 5452 KB Output is correct
5 Correct 5 ms 5452 KB Output is correct
6 Correct 5 ms 5452 KB Output is correct
7 Correct 5 ms 5324 KB Output is correct
8 Correct 5 ms 5448 KB Output is correct
9 Correct 4 ms 5452 KB Output is correct
10 Correct 4 ms 5324 KB Output is correct
11 Correct 5 ms 5452 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 5 ms 5444 KB Output is correct
14 Correct 5 ms 5452 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 6 ms 5452 KB Output is correct
17 Correct 5 ms 5452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5324 KB Output is correct
2 Correct 3 ms 5324 KB Output is correct
3 Correct 4 ms 5324 KB Output is correct
4 Correct 4 ms 5452 KB Output is correct
5 Correct 5 ms 5452 KB Output is correct
6 Correct 5 ms 5452 KB Output is correct
7 Correct 5 ms 5324 KB Output is correct
8 Correct 5 ms 5448 KB Output is correct
9 Correct 4 ms 5452 KB Output is correct
10 Correct 4 ms 5324 KB Output is correct
11 Correct 5 ms 5452 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 5 ms 5444 KB Output is correct
14 Correct 5 ms 5452 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 6 ms 5452 KB Output is correct
17 Correct 5 ms 5452 KB Output is correct
18 Correct 10 ms 5448 KB Output is correct
19 Correct 14 ms 5444 KB Output is correct
20 Correct 13 ms 5452 KB Output is correct
21 Correct 11 ms 5452 KB Output is correct
22 Correct 10 ms 5448 KB Output is correct
23 Correct 11 ms 5564 KB Output is correct
24 Correct 10 ms 5452 KB Output is correct
25 Correct 12 ms 5452 KB Output is correct
26 Correct 11 ms 5440 KB Output is correct
27 Correct 15 ms 5444 KB Output is correct
28 Correct 14 ms 5452 KB Output is correct
29 Correct 12 ms 5448 KB Output is correct
30 Correct 12 ms 5452 KB Output is correct
31 Correct 10 ms 5396 KB Output is correct
32 Correct 11 ms 5448 KB Output is correct
33 Correct 11 ms 5452 KB Output is correct
34 Correct 10 ms 5444 KB Output is correct
35 Correct 9 ms 5452 KB Output is correct
36 Correct 11 ms 5452 KB Output is correct
37 Correct 10 ms 5452 KB Output is correct
38 Correct 11 ms 5324 KB Output is correct
39 Correct 14 ms 5448 KB Output is correct
40 Correct 11 ms 5452 KB Output is correct
41 Correct 14 ms 5448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5452 KB Output is correct
2 Execution timed out 603 ms 5424 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5324 KB Output is correct
2 Correct 3 ms 5324 KB Output is correct
3 Correct 4 ms 5324 KB Output is correct
4 Correct 4 ms 5452 KB Output is correct
5 Correct 5 ms 5452 KB Output is correct
6 Correct 5 ms 5452 KB Output is correct
7 Correct 5 ms 5324 KB Output is correct
8 Correct 5 ms 5448 KB Output is correct
9 Correct 4 ms 5452 KB Output is correct
10 Correct 4 ms 5324 KB Output is correct
11 Correct 5 ms 5452 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 5 ms 5444 KB Output is correct
14 Correct 5 ms 5452 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 6 ms 5452 KB Output is correct
17 Correct 5 ms 5452 KB Output is correct
18 Correct 10 ms 5448 KB Output is correct
19 Correct 14 ms 5444 KB Output is correct
20 Correct 13 ms 5452 KB Output is correct
21 Correct 11 ms 5452 KB Output is correct
22 Correct 10 ms 5448 KB Output is correct
23 Correct 11 ms 5564 KB Output is correct
24 Correct 10 ms 5452 KB Output is correct
25 Correct 12 ms 5452 KB Output is correct
26 Correct 11 ms 5440 KB Output is correct
27 Correct 15 ms 5444 KB Output is correct
28 Correct 14 ms 5452 KB Output is correct
29 Correct 12 ms 5448 KB Output is correct
30 Correct 12 ms 5452 KB Output is correct
31 Correct 10 ms 5396 KB Output is correct
32 Correct 11 ms 5448 KB Output is correct
33 Correct 11 ms 5452 KB Output is correct
34 Correct 10 ms 5444 KB Output is correct
35 Correct 9 ms 5452 KB Output is correct
36 Correct 11 ms 5452 KB Output is correct
37 Correct 10 ms 5452 KB Output is correct
38 Correct 11 ms 5324 KB Output is correct
39 Correct 14 ms 5448 KB Output is correct
40 Correct 11 ms 5452 KB Output is correct
41 Correct 14 ms 5448 KB Output is correct
42 Correct 3 ms 5452 KB Output is correct
43 Execution timed out 603 ms 5424 KB Time limit exceeded
44 Halted 0 ms 0 KB -