QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#229939#7635. Fairy Chessucup-team1516#WA 439ms40136kbC++173.7kb2023-10-28 17:17:072023-10-28 17:17:07

Judging History

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

  • [2023-10-28 17:17:07]
  • 评测
  • 测评结果:WA
  • 用时:439ms
  • 内存:40136kb
  • [2023-10-28 17:17:07]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

ull bit(int x) {
    return ((ull)1 << x);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    auto cid = [&](int x, int y) -> int {
        return x*8+y;
    };

    vector<ull> hi(64),ka(64),ke(64);
    for (int i = 0; i < 8; ++i) {
        for (int j = 0; j < 8; ++j) {
            int id = cid(i,j);

            for (int k = 0; k < 8; ++k) {
                for (int l = 0; l < 8; ++l) {
                    int nid = cid(k,l);
                    if (k == i or j == l) {
                        hi[id] |= bit(nid);
                    }
                    if (i+j == k+l or i-j == k-l) {
                        ka[id] |= bit(nid);
                    }
                    if (abs(k-i) == 1 and abs(j-l) == 2) {
                        ke[id] |= bit(nid);
                    }
                    if (abs(k-i) == 2 and abs(j-l) == 1) {
                        ke[id] |= bit(nid);
                    }
                }
            }
        }
    }

    vector<pair<int,int>> init(64);
    for (int i = 0; i < 64; ++i) {
        init[i] = {i/8, i%8};
    }

    string str = "BBAARRCCQQMM";
    cin >> str;
    vector<pair<int,int>> pre;
    map<pair<vector<pair<int,int>>,int>,bool> mp;

    auto slv = [&](auto slv, vector<pair<int,int>> v, int i) -> bool {
        if (mp.find({v,i}) != mp.end()) {
            return mp[{v,i}];
        }

        char c = str[i];
        bool hisya = (c == 'R' or c == 'Q' or c == 'C' or c == 'M');
        bool kaku = (c == 'B' or c == 'Q' or c == 'A' or c == 'M');
        bool keima = (c == 'A' or c == 'C' or c == 'M');

        for (auto &[j,k] : v) {
            vector<pair<int,int>> nv;

            // preを攻撃しないか
            bool ok = true;
            for (auto &[l, m] : pre) {
                if (hisya) {
                    if (j == l or k == m) {
                        ok = false;
                        break;
                    }
                }
                if (kaku) {
                    if (j+k == l+m or j-k == l-m) {
                        ok = false;
                        break;
                    }
                }
                if (keima) {
                    int u1 = abs(j-l);
                    int u2 = abs(k-m);
                    if (u1 > u2) swap(u1, u2);
                    if (u1 == 1 and u2 == 2) {
                        ok = false;
                        break;
                    }
                }
            }
            if (!ok) continue;

            // nvの更新
            ull ng = 0;
            int id = cid(j, k);
            if (hisya) ng |= hi[id];
            if (kaku) ng |= ka[id];
            if (keima) ng |= ke[id];
            for (auto &[l, m] : v) {
                if (ng&bit(cid(l,m))) continue;
                nv.push_back({l,m});
            }
            pre.push_back({j, k});

            auto res = slv(slv, nv, i+1);

            pre.pop_back();

            if (!res) {
                mp[{v,i}] = true;
                return true;
            }
        }
        mp[{v,i}] = false;
        return false;
    };

    if (slv(slv, init, 0)) {
        cout << "Alice" << endl;
    }
    else {
        cout << "Bob" << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 439ms
memory: 40136kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 24ms
memory: 5768kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: 0
Accepted
time: 11ms
memory: 4644kb

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

score: 0
Accepted
time: 33ms
memory: 7464kb

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

score: 0
Accepted
time: 18ms
memory: 5288kb

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

score: -100
Wrong Answer
time: 100ms
memory: 11828kb

input:

MRCMABRQCQAB

output:

Bob

result:

wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'