QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1248 | #780562 | #9549. The Magician | Imakf | Imakf | Failed. | 2024-11-25 11:35:01 | 2024-11-25 11:41:09 |
Details
Extra Test:
Accepted
time: 0ms
memory: 3648kb
input:
3 38 3C 2C AC 9H 8H 7H 6H 5H 4H 3H 2H AH KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AD KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS 1 1 0 0 0 1 21 AC 2H AH 8D 7D 6D 5D 4D 3D 2D AD TS 9S 8S 7S 6S 5S 4S 3S 2S AS 1 0 0 0 0 0 35 4C 3C 2C AC 9H 8H 7H 6H 5H 4H 3H 2H AH 9D 8D 7D 6D 5D 4D 3D 2D AD KS QS JS TS 9S 8S 7S 6...
output:
7 4 7
result:
ok 3 lines
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#780562 | #9549. The Magician | Imakf | AC ✓ | 0ms | 3724kb | C++23 | 2.9kb | 2024-11-25 11:34:19 | 2024-11-27 17:59:16 |
answer
// https://codeforces.com/gym/105540/submission/292870166
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int tot[5],record[3];
bool tag[10],cop[5],vis[5];
int n,ans1,ans2;
string s;
void init()
{
for(int i=1;i<=6;i++) tag[i]=false;
for(int i=1;i<=4;i++) cop[i]=false,tot[i]=0,vis[i]=false;
}
/* void check()
{
bool flag6=tag[6],flag5=tag[5];
int cnt=0;
int num1=tot[record[1]],num2=tot[record[2]];
for(int i=1;i<=4;i++)
if(!vis[i]) cnt+=tot[i];
int x1=5-num1,x2=5-num2;
//if(cnt+num2<x1) return ;
if(tag[record[1]])
{
int tmp=min(x1,3);
cnt-=tmp;
x1-=tmp;
}
if(x1&&tag[6]&&(cop[record[1]]||tag[record[1]]))
{
x1--;
cnt--;
flag6=false;
}
if(x1&&tag[5])
{
x1--;
cnt--;
flag5=false;
}
if(x1==0&&cnt+num2>=0) ans1=max(ans1,1);
else return;
if(cnt<x2) return ;
if(tag[record[2]]) x2-=min(x2,3);
if(x2&&flag6&&(cop[record[2]]||tag[record[2]]))
x2--;
if(x2&&flag5) x2--;
if(x2==0) ans1=max(ans1,2);
return ;
} */
void check()
{
bool flag6=tag[6],flag5=tag[5];
int num[6],x[5],cnt=0;
for(int i=1;i<=3;i++)
{
num[i]=tot[record[i]];
x[i]=5-num[i];
}
num[4]=num[5]=0;
for(int i=3;i>=1;i--) num[i]+=num[i+1];
cnt=ans2-num[1];
for(int i=1;i<=3;i++)
{
if(cnt+num[i+1]<x[i]) return ;
if(tag[record[i]])
{
int tmp=min(x[i],3);
cnt-=tmp;
x[i]-=tmp;
}
if(x[i]&&flag6&&(cop[record[i]]||tag[record[i]]))
{
x[i]--;
cnt--;
flag6=false;
}
if(x[i]&&flag5)
{
x[i]--;
cnt--;
flag5=false;
}
if(x[i]==0) ans1=max(ans1,i);
else return;
}
}
void dfs(int u)
{
if(u==4)
{
check();
return ;
}
for(int i=1;i<=4;i++)
{
if(vis[i]) continue;
record[u]=i;
vis[i]=true;
dfs(u+1);
vis[i]=false;
}
}
void solve()
{
init();
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s;
char y=s[1];
if(y=='D') tot[1]++;
if(y=='C') tot[2]++;
if(y=='H') tot[3]++;
if(y=='S') tot[4]++;
}
for(int i=1;i<=6;i++)
{
int x;
cin>>x;
if(x) tag[i]=true;
}
ans1=0,ans2=0;
for(int i=1;i<=4;i++)
{
if(tot[i]) cop[i]=true;
tot[i]%=5;
}
for(int i=1;i<=4;i++) ans2+=tot[i];
if(ans2>=5) dfs(1);
ans2=(n-ans2)/5;
cout<<ans1+ans2<<endl;
return ;
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--) solve();
return 0;
}