QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#896027#9549. The Magicianji_114514#WA 176ms3584kbC++202.3kb2025-02-12 20:53:092025-02-12 20:53:09

Judging History

This is the latest submission verdict.

  • [2025-02-12 20:53:09]
  • Judged
  • Verdict: WA
  • Time: 176ms
  • Memory: 3584kb
  • [2025-02-12 20:53:09]
  • Submitted

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);
        }
        sort(c.begin(), c.end());
        bool ok = 1;
        for (auto k : v)if (k == c)ok = 0;
        if (ok)v.push_back(c);
    }
    int temp = 0;
    for (int j = 0; j < 4; j++)temp += cnt[j] / 5, cnt[j] %= 5;
    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 + temp << '\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: 14ms
memory: 3584kb

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
Wrong Answer
time: 176ms
memory: 3584kb

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 ...

output:

2
1
2
2
2
2
1
1
1
1
0
0
0

result:

wrong answer 8th lines differ - expected: '2', found: '1'