QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465362#4523. It's Raining, Man / Ancient CardsDimmytWA 7ms3644kbC++174.1kb2024-07-06 20:21:572024-07-06 20:21:58

Judging History

你现在查看的是最新测评结果

  • [2024-07-06 20:21:58]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3644kb
  • [2024-07-06 20:21:57]
  • 提交

answer

#include <cstdio>
#include <random>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <chrono>


#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

// вправо, вниз, влево, вверх
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

// ход конем
//int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
//int dy[] = {1, 2, 2, 1, -1, -2, -2, -1};

mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::system_clock::now().time_since_epoch().count());
int rndInteger (int l, int r) {
    return uniform_int_distribution<int> (l, r)(rnd);
}

const int MOD = (int) 998244353;
const int N = (int) 1e6 + 7;

int grank(char c) {
    if (c == 'A') return 0;
    if (c == 'X') return 1;
    if ('2' <= c && c <= '9') return c-'0';
    if (c == 'J') return 10;
    if (c == 'Q') return 11;
    if (c == 'K') return 12;
}

int gsuit(char c) {
    if (c == 'C') return 0;
    if (c == 'H') return 1;
    if (c == 'D') return 2;
    if (c == 'S') return 3;
}

int n;

bool has(int msk, int i) {
    return (msk >> i) & 1;
}

inline void solve(){
    vector<int> cnt(4), g(4);
    vector<int> r;
    for (int i = 1; i <= n; i++) {
        char a, b;
        cin >> a >> b;
        a = grank(a);
        b = gsuit(b);

        if (!cnt[b]) r.pb(b);

        cnt[b]++;
        g[b] ^= 1 << a;
    }
    if (sz(r) == 1) {
        cout << "YES\n";
        return;
    }

    vector<int> ind;
    for (int i = 0; i < sz(r); i++) ind.pb(i);

    do {
        int last = g[r[ind[0]]] & g[r[ind[1]]];
        if (last) {
            bool ok = true;
            for (int i = 2; i < sz(ind); i++) {
                int x = r[ind[i]];
                int y = r[ind[i - 1]];
                int q = g[y];
                if (cnt[y] > 1 && __builtin_popcount(last) == 1) {
                    q ^= last;
                }

                last = q & g[x];
                if (!last) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << "YES" << '\n';
                return;
            }
        }

        if(sz(r) == 4) {
            for (int ac = 0; ac < 13; ++ac) if(has(g[ind[2]], ac)){
                for (int bc = 0; bc < 13; ++bc) if(ac != bc && has(g[ind[2]], bc)) {
                    if(has(g[ind[0]], ac) && has(g[ind[1]], bc)) {
                        int leftC = g[ind[2]];
                        assert(has(leftC, ac));
                        assert(has(leftC, bc));
                        leftC ^= (1 << ac);
                        leftC ^= (1 << bc);

                        int leftB = g[ind[1]];
                        assert(has(leftB, bc));
                        leftB ^= (1 << bc);
                        int leftD = g[ind[3]];
                        last = (leftC & leftB);
                        if (!last) continue;

                        if (__builtin_popcount(last) == 1) {
                            leftC ^= last;
                        }

                        if((leftC & leftD) > 0) {
                            cout << "YES\n";
                            return;
                        }

                    }
                }
            }
        }
    }while (next_permutation(all(ind)));

    cout << "NO" << '\n';
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    while(cin >> n) solve();


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 3644kb

input:

37 2S 3S 4S 6S 7S 8S 9S XS JS QS KS AS 5D 2H 3H 4H 6H 7H 8H 9H XH JH QH KH AH 2C 3C 4C 6C 7C 8C 9C XC JC QC KC AC
36 3S 4S 6S 7S 8S 9S XS JS QS KS AS 5D 2H 3H 4H 6H 7H 8H 9H XH JH QH KH AH 2C 3C 4C 6C 7C 8C 9C XC JC QC KC AC
36 2S 4S 6S 7S 8S 9S XS JS QS KS AS 5D 2H 3H 4H 6H 7H 8H 9H XH JH QH KH AH ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

wrong answer 347th lines differ - expected: 'YES', found: 'NO'