QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#896025 | #9549. The Magician | ji_114514# | TL | 207ms | 3712kb | C++20 | 2.1kb | 2025-02-12 20:50:35 | 2025-02-12 20:50:45 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
int n; cin >> n;
vector<int>t(6), cnt(4);
map<char, int>ha;
ha['D'] = 0, ha['C'] = 1, ha['H'] = 2, ha['C'] = 3;
while (n--) {
string s; cin >> s;
cnt[ha[s[1]]]++;
}
for (int i = 0; i < 6; i++)cin >> t[i];
vector<vector<int>>v;
for (int k = 0; k < 64; k++) {
vector<int>c;
for (int j = 0, st = k; j < 3; j++, st /= 4) {
if (st % 4)c.push_back(st % 4);
}
bool ok = 1;
for (auto k : v)if (k == c)ok = 0;
if (ok)v.push_back(c);
}
int res = 0;
auto dfs = [&](auto && self, int i, vector<int>cnt)->void{
for (int j = 0; j < 4; j++) {
int t = cnt[j] + (i <= j) * 3 + 2;
if (t < 0)return;
}
if (i == 6) {
int ans = 0 ;
for (int j = 0; j < 4; j++) {
if (cnt[j] < 0)return;
ans += cnt[j] / 5;
}
res = max(res, ans);
return;
}
else if (i >= 4) {
self(self, i + 1, cnt);
if (t[i]) {
for (int k = 0; k < 4; k++)
for (int j = k + 1; j < 4; j++) {
cnt[k]--, cnt[j]++;
self(self, i + 1, cnt);
cnt[k]++, cnt[j]--;
}
}
}
else{
self(self, i + 1, cnt);
if (t[i]) {
for (auto c : v) {
for (auto t : c) {
cnt[(t + i) % 4]--;
cnt[i]++;
}
self(self, i + 1, cnt);
for (auto t : c) {
cnt[(t + i) % 4]++;
cnt[i]--;
}
}
}
}
};
dfs(dfs, 0, cnt);
cout << res << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1; cin >> t;
while (t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 207ms
memory: 3712kb
input:
4 5 2H 3H 4H 5H 6D 1 1 1 1 0 0 5 2S 3S 4D 5C 6D 0 0 1 0 1 1 5 2S 3S 4D 5C 6D 0 0 1 0 1 0 13 AS 2S 3S 4S 5H 6H 7H 8H 9H TH JH QH KH 0 0 0 0 0 1
output:
1 1 0 2
result:
ok 4 lines
Test #2:
score: -100
Time Limit Exceeded
input:
13 10 AD 2D 3D 4D 5D 6D 7D 8D 9D TD 0 0 1 0 0 0 10 AH 2D 3D 4D 5D 6D 7D 8D 9D TD 0 0 1 0 0 0 10 AH 2H 3D 4D 5D 6D 7D 8D 9D TD 0 0 1 0 0 0 10 AH 2H 3H 4D 5D 6D 7D 8D 9D TD 0 0 1 0 0 0 10 AH 2H 3H 4H 5D 6D 7D 8D 9D TD 0 0 1 0 0 0 10 AS 2S 3S 4S 5S 6S 7S 8S 9S TS 0 1 0 0 0 0 10 AC 2S 3S 4S 5S 6S 7S 8S ...