QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#229781 | #7635. Fairy Chess | ucup-team1055# | AC ✓ | 443ms | 3824kb | C++20 | 4.3kb | 2023-10-28 16:54:01 | 2023-10-28 16:54:02 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<class T>
bool chmin(T &a, T b) {
if(a <= b) return false;
a = b;
return true;
}
template<class T>
bool chmax(T &a, T b) {
if(a >= b) return false;
a = b;
return true;
}
using namespace std;
constexpr int id(int x, int y){
return (x << 3) | y;
}
constexpr bool in(int x, int y){
return 0 <= x && x < 8 && 0 <= y && y < 8;
}
array<int,4> dnight = {-1,1,-2,2};
array<int,2> dbishop = {-1,1};
array<int,3> drook = {-1,0,1};
void print_board(ull a){
rep(i,0,8){
ull b = a & 255ULL;
cout << bitset<8>(b).to_string() << endl;
a >>= 8;
}
cout << "--------" << endl;
}
int main(){
// A, B, C, M, Q, R;
using ar = array<array<ull,8>,8>;
ar Night;
rep(x,0,8) rep(y,0,8){
ull s = 1ULL << id(x,y);
for (int dx : dnight) for (int dy : dnight){
if (abs(dx) == abs(dy)) continue;
int p = x + dx;
int q = y + dy;
if (in(p,q)) s |= 1ULL << id(p,q);
}
Night[x][y] = s;
}
ar Bishop;
rep(x,0,8) rep(y,0,8){
ull s = 1ULL << id(x,y);
for (int dx : dbishop) for (int dy : dbishop){
int p = x;
int q = y;
while (in(p,q)){
s |= 1ULL << id(p,q);
p += dx;
q += dy;
}
}
Bishop[x][y] = s;
}
ar Rook;
rep(x,0,8) rep(y,0,8){
ull s = 1ULL << id(x,y);
for (int dx : drook) for (int dy : drook){
if (dx == 0 && dy == 0) continue;
if (dx != 0 && dy != 0) continue;
int p = x;
int q = y;
while (in(p,q)){
s |= 1ULL << id(p,q);
p += dx;
q += dy;
}
}
Rook[x][y] = s;
}
// print_board(Night[2][3]);
// print_board(Bishop[2][3]);
// print_board(Rook[2][3]);
// A, B, C, M, Q, R;
ar A, B, C, M, Q, R;
rep(x,0,8) rep(y,0,8){
A[x][y] = Bishop[x][y] | Night[x][y];
B[x][y] = Bishop[x][y];
C[x][y] = Rook[x][y] | Night[x][y];
M[x][y] = Bishop[x][y] | Rook[x][y] | Night[x][y];
Q[x][y] = Bishop[x][y] | Rook[x][y];
R[x][y] = Rook[x][y];
}
// print_board(A[2][3]);
// print_board(B[2][3]);
// print_board(C[2][3]);
// print_board(M[2][3]);
// print_board(Q[2][3]);
// print_board(R[2][3]);
array<ar,6> board = {A,B,C,M,Q,R};
vector<int> a = [&]{
string s; cin >> s;
vector<int> b(12);
rep(i,0,12){
if (s[i] == 'A') b[i] = 0;
else if (s[i] == 'B') b[i] = 1;
else if (s[i] == 'C') b[i] = 2;
else if (s[i] == 'M') b[i] = 3;
else if (s[i] == 'Q') b[i] = 4;
else if (s[i] == 'R') b[i] = 5;
}
return b;
}();
// if alice win -> true
auto dfs = [&](auto sfs, int i, ull b, ull ng) -> bool {
if (i % 2 == 0){
bool res = false;
rep(x,0,8){
rep(y,0,8){
if (ng >> id(x,y) & 1) continue;
if (b & board[a[i]][x][y]) continue;
if ( sfs(sfs,i+1, b | (1ULL << id(x,y)), ng | board[a[i]][x][y]) ){
res = true;
break;
}
}
if (res) break;
}
return res;
}
else {
bool res = false;
rep(x,0,8){
rep(y,0,8){
if (ng >> id(x,y) & 1) continue;
if (b & board[a[i]][x][y]) continue;
if ( !sfs(sfs,i+1, b | (1ULL << id(x,y)), ng | board[a[i]][x][y]) ){
res = true;
break;
}
}
if (res) break;
}
return !res;
}
};
bool ans = dfs(dfs,0,0,0);
cout << (ans ? "Alice" : "Bob") << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 42ms
memory: 3524kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3520kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 5ms
memory: 3780kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3524kb
input:
MRCMABRQCQAB
output:
Alice
result:
ok single line: 'Alice'
Test #7:
score: 0
Accepted
time: 6ms
memory: 3780kb
input:
BBRCMMQAAQRC
output:
Alice
result:
ok single line: 'Alice'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
RRMCQMACABQB
output:
Alice
result:
ok single line: 'Alice'
Test #9:
score: 0
Accepted
time: 4ms
memory: 3596kb
input:
QMQBMRBACACR
output:
Alice
result:
ok single line: 'Alice'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3748kb
input:
CMRQAQCBBRAM
output:
Alice
result:
ok single line: 'Alice'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3824kb
input:
CABCRQMMRQAB
output:
Alice
result:
ok single line: 'Alice'
Test #12:
score: 0
Accepted
time: 17ms
memory: 3528kb
input:
ARCBBCMQRAQM
output:
Alice
result:
ok single line: 'Alice'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
ARCMCARMQBBQ
output:
Alice
result:
ok single line: 'Alice'
Test #14:
score: 0
Accepted
time: 11ms
memory: 3552kb
input:
AQABMCQCMRRB
output:
Bob
result:
ok single line: 'Bob'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
ACMRABRQMCBQ
output:
Alice
result:
ok single line: 'Alice'
Test #16:
score: 0
Accepted
time: 12ms
memory: 3780kb
input:
CBARMBCQMQAR
output:
Bob
result:
ok single line: 'Bob'
Test #17:
score: 0
Accepted
time: 18ms
memory: 3528kb
input:
RBABRQMCAMQC
output:
Bob
result:
ok single line: 'Bob'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
MBCQBQARRMCA
output:
Alice
result:
ok single line: 'Alice'
Test #19:
score: 0
Accepted
time: 8ms
memory: 3588kb
input:
AMBQRBCQACMR
output:
Bob
result:
ok single line: 'Bob'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
QRAMQMBBCRAC
output:
Alice
result:
ok single line: 'Alice'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3588kb
input:
ARBCQMMBARQC
output:
Alice
result:
ok single line: 'Alice'
Test #22:
score: 0
Accepted
time: 30ms
memory: 3600kb
input:
CACAMBRQQRBM
output:
Bob
result:
ok single line: 'Bob'
Test #23:
score: 0
Accepted
time: 9ms
memory: 3592kb
input:
CQRRMMBQABCA
output:
Bob
result:
ok single line: 'Bob'
Test #24:
score: 0
Accepted
time: 11ms
memory: 3812kb
input:
ABABCQRMMCRQ
output:
Alice
result:
ok single line: 'Alice'
Test #25:
score: 0
Accepted
time: 5ms
memory: 3808kb
input:
CMBRAAQRQMBC
output:
Bob
result:
ok single line: 'Bob'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
AQBMRMQRBACC
output:
Alice
result:
ok single line: 'Alice'
Test #27:
score: 0
Accepted
time: 7ms
memory: 3604kb
input:
BRACQQMCAMBR
output:
Bob
result:
ok single line: 'Bob'
Test #28:
score: 0
Accepted
time: 2ms
memory: 3484kb
input:
MCCAQBMQRABR
output:
Bob
result:
ok single line: 'Bob'
Test #29:
score: 0
Accepted
time: 11ms
memory: 3484kb
input:
RBQBCRAACMQM
output:
Bob
result:
ok single line: 'Bob'
Test #30:
score: 0
Accepted
time: 5ms
memory: 3824kb
input:
ACRQARMBBQMC
output:
Bob
result:
ok single line: 'Bob'
Test #31:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
MRCQBCBQRMAA
output:
Alice
result:
ok single line: 'Alice'
Test #32:
score: 0
Accepted
time: 5ms
memory: 3820kb
input:
ACRQQCMMBBAR
output:
Bob
result:
ok single line: 'Bob'
Test #33:
score: 0
Accepted
time: 3ms
memory: 3484kb
input:
MMACQBRQABRC
output:
Bob
result:
ok single line: 'Bob'
Test #34:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
QACMQABRMCBR
output:
Alice
result:
ok single line: 'Alice'
Test #35:
score: 0
Accepted
time: 5ms
memory: 3552kb
input:
ACAQRCMRMBQB
output:
Alice
result:
ok single line: 'Alice'
Test #36:
score: 0
Accepted
time: 3ms
memory: 3592kb
input:
RABQCQMCABMR
output:
Bob
result:
ok single line: 'Bob'
Test #37:
score: 0
Accepted
time: 4ms
memory: 3528kb
input:
QQBARCRBMMAC
output:
Alice
result:
ok single line: 'Alice'
Test #38:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
RQMRQABCABCM
output:
Alice
result:
ok single line: 'Alice'
Test #39:
score: 0
Accepted
time: 2ms
memory: 3780kb
input:
RQAMBRQCCBMA
output:
Alice
result:
ok single line: 'Alice'
Test #40:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
QQBACMARMRBC
output:
Alice
result:
ok single line: 'Alice'
Test #41:
score: 0
Accepted
time: 4ms
memory: 3744kb
input:
QAQCRRAMMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #42:
score: 0
Accepted
time: 4ms
memory: 3524kb
input:
QQBMCBRARMAC
output:
Bob
result:
ok single line: 'Bob'
Test #43:
score: 0
Accepted
time: 54ms
memory: 3820kb
input:
BABARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #44:
score: 0
Accepted
time: 264ms
memory: 3532kb
input:
BBARARCCQQMM
output:
Alice
result:
ok single line: 'Alice'
Test #45:
score: 0
Accepted
time: 22ms
memory: 3748kb
input:
BBAARCRCQQMM
output:
Alice
result:
ok single line: 'Alice'
Test #46:
score: 0
Accepted
time: 64ms
memory: 3780kb
input:
BBAARRCQCQMM
output:
Bob
result:
ok single line: 'Bob'
Test #47:
score: 0
Accepted
time: 42ms
memory: 3824kb
input:
BBAARRCCQMQM
output:
Bob
result:
ok single line: 'Bob'
Test #48:
score: 0
Accepted
time: 141ms
memory: 3820kb
input:
BBAACCRQMQRM
output:
Bob
result:
ok single line: 'Bob'
Test #49:
score: 0
Accepted
time: 148ms
memory: 3820kb
input:
BACBACQRRQMM
output:
Bob
result:
ok single line: 'Bob'
Test #50:
score: 0
Accepted
time: 443ms
memory: 3528kb
input:
RAABBRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #51:
score: 0
Accepted
time: 28ms
memory: 3592kb
input:
RABRBQMCACQM
output:
Bob
result:
ok single line: 'Bob'
Test #52:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
CMMQQABCRABR
output:
Alice
result:
ok single line: 'Alice'
Test #53:
score: 0
Accepted
time: 85ms
memory: 3524kb
input:
RBAABRCCQQMM
output:
Alice
result:
ok single line: 'Alice'
Extra Test:
score: 0
Extra Test Passed