QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1214#755127#9549. The MagicianImakfucup-team191Failed.2024-11-20 17:58:022024-11-20 17:58:02

Details

Extra Test:

Invalid Input

input:

7
19
AH 2H 3H 4H AD 2D 3D 4D 5C 6C 7C 8C 9S TS JS 5H 6H 7H 8H
1 1 1 1 1 1
15
AH 2H 3H 4H AD 2D 3D 4D 5C 6C 7C 8C 9S TS JS
1 1 1 1 1 1
15
AH 2H 3H 4H AD 2D 3D 4D 5C 6C 7C 8C 9S TS JS
1 1 1 1 1 1
15
AH 2H 3H 4H AD 2D 3D 4D 5C 6C 7C 8C 9S TS JS
1 1 1 1 1 1
15
AH 2H 3H 4H AD 2D 3D 4D 5C 6C 7C 8C 9S TS J...

output:


result:

FAIL Sum of all n must not exceed 104 (test case 7)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755127#9549. The Magicianucup-team191#TL 752ms46416kbC++232.0kb2024-11-16 16:31:562024-11-20 19:18:49

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using pii=pair<int,int>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=300010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int t,n;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	while (t--)
	{
		cin>>n;
		vi cn(5);
		for (int i=0;i<n;++i)
		{
			string ti;
			cin>>ti;
			if (ti[1]=='D') ++cn[0];
			if (ti[1]=='C') ++cn[1];
			if (ti[1]=='H') ++cn[2];
			if (ti[1]=='S') ++cn[3];
		}
		vi ty(6);
		for (auto&x: ty) cin>>x;
		set<pair<vi,vi>> s;
		queue<pair<vi,vi>> q;
		q.push({cn,ty});
		int an=0;
		while (q.size())
		{
			vi cc=q.front().x,tt=q.front().y;
			q.pop();
			if (s.count({cc,tt})) continue;
			s.insert({cc,tt});
			int can=0;
			int m4=0,m3=0;
			for (auto x: cc) can+=x/5,m4+=(x%5==4),m3+=(x%5==3);
			if (cc[4]==1)
			{
				if (m4) ++can;
			}
			if (cc[4]==2)
			{
				can+=max(min(m4,2),min(m3,1));
			}
			an=max(an,can);
			for (int z=0;z<4;++z) if (tt[z])
			{
				--tt[z];
				for (int i=0;i<4;++i) if (cc[i])
				{
					--cc[i];
					++cc[z];
					q.push({cc,tt});
					--cc[z];
					for (int j=i;j<4;++j) if (cc[j])
					{
						--cc[j];
						cc[z]+=2;
						q.push({cc,tt});
						cc[z]-=2;
						for (int k=j;k<4;++k) if (cc[k])
						{
							--cc[k];
							cc[z]+=3;
							q.push({cc,tt});
							cc[z]-=3;
							++cc[k];
						}
						++cc[j];
					}
					++cc[i];
				}
				++tt[z];
			}
			if (tt[4]) for (int i=0;i<4;++i) if (cc[i])
			{
				--tt[4];
				--cc[i];
				++cc[4];
				q.push({cc,tt});
				--cc[4];
				++cc[i];
				++tt[4];
			}
			if (tt[5])
			{
				--tt[5];
				for (int i=0;i<4;++i) for (int j=0;j<5;++j) if (i!=j && cc[i] && cc[j])
				{
					--cc[i];
					++cc[j];
					q.push({cc,tt});
					--cc[j];
					++cc[i];
				}
				++tt[5];
			}
		}
		cout<<an<<en;
	}
}