QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506540#7635. Fairy Chesspandapythoner#AC ✓1168ms139792kbC++233.7kb2024-08-05 19:14:082024-08-05 19:14:10

Judging History

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

  • [2024-08-05 19:14:10]
  • 评测
  • 测评结果:AC
  • 用时:1168ms
  • 内存:139792kb
  • [2024-08-05 19:14:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


using ll = long long;
using ull = unsigned long long;

#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
#define len(a) ((int)(a).size())


const ll inf = 1e18;
mt19937 rnd(234);


string s;


map<char, vector<ull>> mp;
map<array<ull, 3>, bool> dp;

bool get(ull usd, ull captured, int i) {
    assert(i < 12);
    assert((usd & captured) == usd);
    if (i == 12) {
        return false;
    }
    array<ull, 3> arr = { usd, captured, i };
    auto it = dp.find(arr);
    if (it != dp.end()) {
        return it->second;
    }
    bool result = false;
    auto my_capturing = mp[s[i]];
    assert(len(my_capturing) == 64);
    for (int pos = 0; pos < 64; pos += 1) {
        if ((captured >> pos) % 2 == 1) continue;
        if ((my_capturing[pos] & usd) != 0) continue;
        if ((usd >> pos) % 2 == 1) continue;
        ull nusd = usd | (ull(1) << pos);
        ull ncaptured = captured | my_capturing[pos];
        if (!get(nusd, ncaptured, i + 1)) {
            result = true;
            break;
        }
    }
    dp[arr] = result;
    return result;
}



int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    mp.clear();
    for (char c : string("RBQKACM")) {
        vector<ull> capturing(64);
        if (c == 'R') {
            rep(x, 8) rep(y, 8) {
                capturing[x * 8 + y] = 0;
                rep(i, 8) {
                    capturing[x * 8 + y] |= (ull(1) << (x * 8 + i));
                    capturing[x * 8 + y] |= (ull(1) << (i * 8 + y));
                }
            }
        } else if (c == 'B') {
            rep(x, 8) rep(y, 8) {
                capturing[x * 8 + y] = 0;
                rep(i, 8) {
                    int dx = abs(x - i);
                    if (y - dx >= 0)
                        capturing[x * 8 + y] |= (ull(1) << (i * 8 + y - dx));

                    if (y + dx < 8)
                        capturing[x * 8 + y] |= (ull(1) << (i * 8 + y + dx));
                }
            }
        } else if (c == 'Q') {
            rep(x, 8) rep(y, 8) {
                capturing[x * 8 + y] = mp['R'][x * 8 + y] | mp['B'][x * 8 + y];
            }
        } else if (c == 'K') {
            rep(x, 8) rep(y, 8) {
                capturing[x * 8 + y] = (ull(1) << (x * 8 + y));
                for (auto [dx, dy] : { make_pair(1, 2), make_pair(2, 1) }) {
                    for (int sdx = -1; sdx <= 1; sdx += 2) {
                        for (int sdy = -1; sdy <= 1; sdy += 2) {
                            int nx = x + dx * sdx;
                            int ny = y + dy * sdy;
                            if (0 <= nx and nx < 8 and 0 <= ny and ny < 8) {
                                capturing[x * 8 + y] |= (ull(1) << (nx * 8 + ny));
                            }
                        }
                    }
                }
            }
        } else if (c == 'A') {
            rep(x, 8) rep(y, 8) {
                capturing[x * 8 + y] = mp['B'][x * 8 + y] | mp['K'][x * 8 + y];
            }
        } else if (c == 'C') {
            rep(x, 8) rep(y, 8) {
                capturing[x * 8 + y] = mp['R'][x * 8 + y] | mp['K'][x * 8 + y];
            }
        } else if (c == 'M') {
            rep(x, 8) rep(y, 8) {
                capturing[x * 8 + y] = mp['Q'][x * 8 + y] | mp['K'][x * 8 + y];
            }
        }
        mp[c] = capturing;
    }
    cin >> s;
    if (get(0, 0, 0)) {
        cout << "Alice" << "\n";
    } else {
        cout << "Bob" << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 98ms
memory: 21320kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 7ms
memory: 5000kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: 0
Accepted
time: 3ms
memory: 4224kb

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

score: 0
Accepted
time: 13ms
memory: 6104kb

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

score: 0
Accepted
time: 3ms
memory: 4436kb

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

score: 0
Accepted
time: 8ms
memory: 5156kb

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

score: 0
Accepted
time: 15ms
memory: 6204kb

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

score: 0
Accepted
time: 12ms
memory: 6000kb

input:

RRMCQMACABQB

output:

Alice

result:

ok single line: 'Alice'

Test #9:

score: 0
Accepted
time: 13ms
memory: 6188kb

input:

QMQBMRBACACR

output:

Alice

result:

ok single line: 'Alice'

Test #10:

score: 0
Accepted
time: 7ms
memory: 5004kb

input:

CMRQAQCBBRAM

output:

Alice

result:

ok single line: 'Alice'

Test #11:

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

input:

CABCRQMMRQAB

output:

Alice

result:

ok single line: 'Alice'

Test #12:

score: 0
Accepted
time: 35ms
memory: 11588kb

input:

ARCBBCMQRAQM

output:

Alice

result:

ok single line: 'Alice'

Test #13:

score: 0
Accepted
time: 2ms
memory: 4168kb

input:

ARCMCARMQBBQ

output:

Alice

result:

ok single line: 'Alice'

Test #14:

score: 0
Accepted
time: 26ms
memory: 9044kb

input:

AQABMCQCMRRB

output:

Bob

result:

ok single line: 'Bob'

Test #15:

score: 0
Accepted
time: 7ms
memory: 5100kb

input:

ACMRABRQMCBQ

output:

Alice

result:

ok single line: 'Alice'

Test #16:

score: 0
Accepted
time: 39ms
memory: 10800kb

input:

CBARMBCQMQAR

output:

Bob

result:

ok single line: 'Bob'

Test #17:

score: 0
Accepted
time: 51ms
memory: 11604kb

input:

RBABRQMCAMQC

output:

Bob

result:

ok single line: 'Bob'

Test #18:

score: 0
Accepted
time: 2ms
memory: 4004kb

input:

MBCQBQARRMCA

output:

Alice

result:

ok single line: 'Alice'

Test #19:

score: 0
Accepted
time: 21ms
memory: 8484kb

input:

AMBQRBCQACMR

output:

Bob

result:

ok single line: 'Bob'

Test #20:

score: 0
Accepted
time: 1ms
memory: 3964kb

input:

QRAMQMBBCRAC

output:

Alice

result:

ok single line: 'Alice'

Test #21:

score: 0
Accepted
time: 6ms
memory: 4836kb

input:

ARBCQMMBARQC

output:

Alice

result:

ok single line: 'Alice'

Test #22:

score: 0
Accepted
time: 75ms
memory: 17224kb

input:

CACAMBRQQRBM

output:

Bob

result:

ok single line: 'Bob'

Test #23:

score: 0
Accepted
time: 31ms
memory: 9060kb

input:

CQRRMMBQABCA

output:

Bob

result:

ok single line: 'Bob'

Test #24:

score: 0
Accepted
time: 22ms
memory: 8348kb

input:

ABABCQRMMCRQ

output:

Alice

result:

ok single line: 'Alice'

Test #25:

score: 0
Accepted
time: 12ms
memory: 6592kb

input:

CMBRAAQRQMBC

output:

Bob

result:

ok single line: 'Bob'

Test #26:

score: 0
Accepted
time: 2ms
memory: 3968kb

input:

AQBMRMQRBACC

output:

Alice

result:

ok single line: 'Alice'

Test #27:

score: 0
Accepted
time: 20ms
memory: 7440kb

input:

BRACQQMCAMBR

output:

Bob

result:

ok single line: 'Bob'

Test #28:

score: 0
Accepted
time: 7ms
memory: 5148kb

input:

MCCAQBMQRABR

output:

Bob

result:

ok single line: 'Bob'

Test #29:

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

input:

RBQBCRAACMQM

output:

Bob

result:

ok single line: 'Bob'

Test #30:

score: 0
Accepted
time: 14ms
memory: 6056kb

input:

ACRQARMBBQMC

output:

Bob

result:

ok single line: 'Bob'

Test #31:

score: 0
Accepted
time: 2ms
memory: 3952kb

input:

MRCQBCBQRMAA

output:

Alice

result:

ok single line: 'Alice'

Test #32:

score: 0
Accepted
time: 16ms
memory: 6448kb

input:

ACRQQCMMBBAR

output:

Bob

result:

ok single line: 'Bob'

Test #33:

score: 0
Accepted
time: 9ms
memory: 5392kb

input:

MMACQBRQABRC

output:

Bob

result:

ok single line: 'Bob'

Test #34:

score: 0
Accepted
time: 3ms
memory: 4440kb

input:

QACMQABRMCBR

output:

Alice

result:

ok single line: 'Alice'

Test #35:

score: 0
Accepted
time: 15ms
memory: 6376kb

input:

ACAQRCMRMBQB

output:

Alice

result:

ok single line: 'Alice'

Test #36:

score: 0
Accepted
time: 19ms
memory: 7584kb

input:

RABQCQMCABMR

output:

Bob

result:

ok single line: 'Bob'

Test #37:

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

input:

QQBARCRBMMAC

output:

Alice

result:

ok single line: 'Alice'

Test #38:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

RQMRQABCABCM

output:

Alice

result:

ok single line: 'Alice'

Test #39:

score: 0
Accepted
time: 0ms
memory: 4656kb

input:

RQAMBRQCCBMA

output:

Alice

result:

ok single line: 'Alice'

Test #40:

score: 0
Accepted
time: 2ms
memory: 4064kb

input:

QQBACMARMRBC

output:

Alice

result:

ok single line: 'Alice'

Test #41:

score: 0
Accepted
time: 14ms
memory: 6356kb

input:

QAQCRRAMMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #42:

score: 0
Accepted
time: 7ms
memory: 5956kb

input:

QQBMCBRARMAC

output:

Bob

result:

ok single line: 'Bob'

Test #43:

score: 0
Accepted
time: 89ms
memory: 17848kb

input:

BABARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #44:

score: 0
Accepted
time: 474ms
memory: 63752kb

input:

BBARARCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #45:

score: 0
Accepted
time: 47ms
memory: 11976kb

input:

BBAARCRCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #46:

score: 0
Accepted
time: 141ms
memory: 26148kb

input:

BBAARRCQCQMM

output:

Bob

result:

ok single line: 'Bob'

Test #47:

score: 0
Accepted
time: 104ms
memory: 21320kb

input:

BBAARRCCQMQM

output:

Bob

result:

ok single line: 'Bob'

Test #48:

score: 0
Accepted
time: 342ms
memory: 51684kb

input:

BBAACCRQMQRM

output:

Bob

result:

ok single line: 'Bob'

Test #49:

score: 0
Accepted
time: 457ms
memory: 67744kb

input:

BACBACQRRQMM

output:

Bob

result:

ok single line: 'Bob'

Test #50:

score: 0
Accepted
time: 1168ms
memory: 139792kb

input:

RAABBRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #51:

score: 0
Accepted
time: 60ms
memory: 15276kb

input:

RABRBQMCACQM

output:

Bob

result:

ok single line: 'Bob'

Test #52:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

CMMQQABCRABR

output:

Alice

result:

ok single line: 'Alice'

Test #53:

score: 0
Accepted
time: 190ms
memory: 33488kb

input:

RBAABRCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Extra Test:

score: 0
Extra Test Passed