QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1202#758368#9549. The MagicianImakflight_ink_dotsSuccess!2024-11-20 00:56:502024-11-20 13:44:55

Details

Extra Test:

Time Limit Exceeded

input:

8
13
7H 7D 8C 8S 9H 9D TC TS JH JD QC QS KH
1 1 1 1 1 1
13
7H 7D 8C 8S 9H 9D TC TS JH JD QC QS KH
1 1 1 1 1 1
13
7H 7D 8C 8S 9H 9D TC TS JH JD QC QS KH
1 1 1 1 1 1
13
7H 7D 8C 8S 9H 9D TC TS JH JD QC QS KH
1 1 1 1 1 1
13
7H 7D 8C 8S 9H 9D TC TS JH JD QC QS KH
1 1 1 1 1 1
13
7H 7D 8C 8S 9H 9D TC TS J...

output:

2
2
2
2
2
2

result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#758368#9549. The Magicianlight_ink_dots#TL 720ms3956kbC++201.6kb2024-11-17 18:04:112024-11-20 13:49:52

answer

//Cut it out, you've already lost.
#include<bits/stdc++.h>
using namespace std;
const int maxn=500005;
int n,m,T,ans,flg;
int cnt[5],t[10];
string s;
void solve(){
	int res=cnt[0]/5+cnt[1]/5+cnt[2]/5+cnt[3]/5;
	int o[5]={0,0,0,0,0},v=cnt[4];
	o[cnt[0]%5]++,o[cnt[1]%5]++,o[cnt[2]%5]++,o[cnt[3]%5]++;
	while(v&&o[4])
		o[4]--,v--,res++;
	while(v>=2&&o[3])
		o[3]--,v-=2,res++;
	ans=max(ans,res);
}
void dfs(int typ){
	if(typ==0){
		if(t[5]){
			for(int i=0;i<=3;i++)
				if(cnt[i]){
					cnt[i]--,cnt[4]++;
					dfs(typ+1);
					cnt[i]++,cnt[4]--;
				}
		}
		dfs(typ+1);
	}
	if(typ==1){
		if(t[6])
			for(int i=0;i<=3;i++)
				if(cnt[i])
					for(int j=0;j<=4;j++){
						cnt[i]--,cnt[j]++;
						dfs(typ+1);
						cnt[i]++,cnt[j]--;
					}
		dfs(typ+1);
	}
	if(typ>=2&&typ<=5){
		if(t[typ-1]){
			for(int i=0;i<=3;i++)
				for(int j=i;j<=3;j++)
					for(int k=j;k<=3;k++){
						cnt[typ-2]+=3;
						cnt[i]--,cnt[j]--,cnt[k]--;
						if(cnt[i]>=0&&cnt[j]>=0&&cnt[k]>=0){
							dfs(typ+1);
							cnt[typ-2]-=3;
						}
						else cnt[typ-2]-=3;
						cnt[i]++,cnt[j]++,cnt[k]++;
					}
		}
		dfs(typ+1);
	}
	if(typ==6)
		solve();
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n),ans=cnt[0]=cnt[1]=cnt[2]=cnt[3]=cnt[4]=0;
		for(int i=1;i<=n;i++){
			cin>>s;
			cnt[s[1]=='D'? 0:(s[1]=='C'? 1:(s[1]=='H'? 2:3))]/*[s[0]<='9'? (s[0]-48):(s[0]=='T'? 10:(s[0]=='J'? 11:(s[0]=='Q'? 12:(s[0]=='K'? 13:1))))]*/++;
		}
		for(int i=1;i<=6;i++)
			scanf("%d",&t[i]);
		dfs(0);
		printf("%d\n",ans);
	}
	return 0;
}