QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1262 | #788369 | #9549. The Magician | Imakf | Traveler | Success! | 2024-11-27 17:54:58 | 2024-11-27 17:54:59 |
Details
Extra Test:
Wrong Answer
time: 0ms
memory: 3528kb
input:
3 17 AH 3D 2D AD KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS 1 0 0 0 1 1 25 4C 3C 2C AC 4H 3H 2H AH 8D 7D 6D 5D 4D 3D 2D AD 9S 8S 7S 6S 5S 4S 3S 2S AS 0 1 1 0 1 0 42 6C 5C 4C 3C 2C AC TH 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 1 1 1 1
output:
3 4 8
result:
wrong answer 2nd lines differ - expected: '5', found: '4'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788369 | #9549. The Magician | Traveler | WA | 1ms | 3872kb | C++20 | 5.8kb | 2024-11-27 16:42:26 | 2024-11-27 17:59:25 |
answer
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<unordered_map>
#include<vector>
#include<array>
#include<math.h>
#include<map>
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<string>
#include<limits.h>
#include<stack>
#include<set>
#include<list>
#include<algorithm>
#include <chrono>
#include<random>
using namespace std;
typedef long long LL;
#define int long long
typedef unsigned long long ULL;
typedef pair<LL, LL>PII;
typedef pair<double, double>PDD;
typedef pair<char, char>PCC;
LL n, m, k;
const LL inf = 1e18;
const LL N = 1e6 + 10;
const LL mod = 1e9 + 7;
void solve() {
cin >> n;
auto id = [&](char x)->int {
if (x == 'D')return 0;
if (x == 'C')return 1;
if (x == 'H')return 2;
return 3;
};
vector<int>cnt(5);
for (int i = 1;i <= n;i++) {
string s;cin >> s;
cnt[id(s[1])]++;
}
int ans = 0;
int w = 0;
for (int i = 0;i < 4;i++) {
int t = cnt[i] / 5;
w += t;
cnt[i] %= 5;
}
vector<int>t(10);
for (int i = 0;i < 6;i++)cin >> t[i];
for (int st = 0;st < (1 << 4);st++) {
set<int>op;
int res = w;
int t5 = t[4];
int t6 = t[5];
for (int k = 0;k < 4;k++) {
if ((st >> k & 1) && t[k]) {
op.insert(k);
}
}
vector<int>p, np;
for (auto x : op) {
p.push_back(cnt[x]);
}
for (int j = 0;j < 4;j++) {
if (op.count(j)||cnt[j]==0)continue;
np.push_back(cnt[j]);
}
sort(p.begin(), p.end(), greater());
sort(np.begin(), np.end());
int idx = 0;
int rest = 0;
for (auto x : p) {
int now = rest;
while (idx < np.size() && np[idx] == 0) {
idx++;
}
while (idx<np.size()&&now < 3) {
int d = 3 - now;
if (d < np[idx]) {
np[idx] -= d;
now += d;
break;
}
else {
now += np[idx];
np[idx] = 0;
idx++;
}
}
while (idx < np.size() && np[idx] == 0) {
idx++;
}
rest = 0;
if (now > 3) {
x += 3;
rest = now - 3;
}
else {
x += now;
}
if (x >= 5) {
x -= 5;
res++;
}
else {
if (t6) {
if (idx < np.size() && np[idx]) {
np[idx]--;
if (np[idx] == 0)idx++;
t6 = 0;
x++;
}
}
if (x >= 5) {
x -= 5;
res++;
}
else {
if (t5) {
if (idx < np.size() && np[idx]) {
np[idx]--;
if (np[idx] == 0)idx++;
t5 = 0;
x++;
}
}
}
if (x >= 5) {
x -= 5;
res++;
}
}
rest = x;
}
int r = np.size()-1;
while (r >= idx&&(t5||t6)) {
while (idx < r && np[idx] == 0) {
idx++;
}
int d = 5 - np[r];
if (d > 2)break;
if (d == 1) {
if (t6) {
if (rest) {
rest--;
r--;
t6 = 0;
res++;
continue;
}
else if (idx < r && np[idx]) {
r--;
res++;
t6 = 0;
np[idx]--;
if (np[idx] == 0)idx++;
continue;
}
}
while (idx < r && np[idx] == 0) {
idx++;
}
if (t5) {
if (rest) {
rest--;
r--;
t5 = 0;
res++;
continue;
}
else if (idx < r && np[idx]) {
r--;
res++;
t5 = 0;
np[idx]--;
if (np[idx] == 0)idx++;
continue;
}
}
break;
}
if (d == 2) {
while (idx <r && np[idx] == 0) {
idx++;
}
if (t5 && t6) {
int d = 0;
while (idx < r) {
d += np[idx];
idx++;
}
if (rest >= 2) {
res++;
}
else if (d >= 2)res++;
}
break;
}
}
ans = max(ans, res);
}
cout << ans << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}