QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1202 | #758368 | #9549. The Magician | Imakf | light_ink_dots | Success! | 2024-11-20 00:56:50 | 2024-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:
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#758368 | #9549. The Magician | light_ink_dots# | TL | 720ms | 3956kb | C++20 | 1.6kb | 2024-11-17 18:04:11 | 2024-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;
}