QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232376 | #7635. Fairy Chess | neko_nyaa | AC ✓ | 922ms | 3520kb | C++23 | 3.5kb | 2023-10-30 12:04:01 | 2023-10-30 12:04:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
bool valid(int x, int y) {
return (x >= 0 && y >= 0 && x < 8 && y < 8);
}
bitset<64> fill(bitset<64> bs, char c, int st) {
int x = st/8, y = st%8;
bs[st] = 1;
// up down
if (c == 'R' || c == 'Q' || c == 'C' || c == 'M') {
for (int i = 0; i < 8; i++) {
if (valid(x-i, y)) {int g = (x-i)*8 + y; bs[g] = 1;}
if (valid(x+i, y)) {int g = (x+i)*8 + y; bs[g] = 1;}
if (valid(x, y-i)) {int g = x*8 + (y-i); bs[g] = 1;}
if (valid(x, y+i)) {int g = x*8 + (y+i); bs[g] = 1;}
}
}
// diagonal
if (c == 'B' || c == 'Q' || c == 'A' || c == 'M') {
for (int i = 0; i < 8; i++) {
if (valid(x-i, y-i)) {int g = (x-i)*8 + (y-i); bs[g] = 1;}
if (valid(x+i, y-i)) {int g = (x+i)*8 + (y-i); bs[g] = 1;}
if (valid(x-i, y+i)) {int g = (x-i)*8 + (y+i); bs[g] = 1;}
if (valid(x+i, y+i)) {int g = (x+i)*8 + (y+i); bs[g] = 1;}
}
}
// knight
if (c == 'A' || c == 'C' || c == 'M') {
if (valid(x-1, y-2)) {int g = (x-1)*8 + (y-2); bs[g] = 1;}
if (valid(x+1, y-2)) {int g = (x+1)*8 + (y-2); bs[g] = 1;}
if (valid(x-1, y+2)) {int g = (x-1)*8 + (y+2); bs[g] = 1;}
if (valid(x+1, y+2)) {int g = (x+1)*8 + (y+2); bs[g] = 1;}
if (valid(x-2, y-1)) {int g = (x-2)*8 + (y-1); bs[g] = 1;}
if (valid(x+2, y-1)) {int g = (x+2)*8 + (y-1); bs[g] = 1;}
if (valid(x-2, y+1)) {int g = (x-2)*8 + (y+1); bs[g] = 1;}
if (valid(x+2, y+1)) {int g = (x+2)*8 + (y+1); bs[g] = 1;}
}
return bs;
}
bool check_attack(bitset<64> ps, char c, int st) {
int x = st/8, y = st%8;
// up down
if (c == 'R' || c == 'Q' || c == 'C' || c == 'M') {
for (int i = 0; i < 8; i++) {
if (valid(x-i, y)) {int g = (x-i)*8 + y; if (ps[g] == 1) return 0;}
if (valid(x+i, y)) {int g = (x+i)*8 + y; if (ps[g] == 1) return 0;}
if (valid(x, y-i)) {int g = x*8 + (y-i); if (ps[g] == 1) return 0;}
if (valid(x, y+i)) {int g = x*8 + (y+i); if (ps[g] == 1) return 0;}
}
}
// diagonal
if (c == 'B' || c == 'Q' || c == 'A' || c == 'M') {
for (int i = 0; i < 8; i++) {
if (valid(x-i, y-i)) {int g = (x-i)*8 + (y-i); if (ps[g] == 1) return 0;}
if (valid(x+i, y-i)) {int g = (x+i)*8 + (y-i); if (ps[g] == 1) return 0;}
if (valid(x-i, y+i)) {int g = (x-i)*8 + (y+i); if (ps[g] == 1) return 0;}
if (valid(x+i, y+i)) {int g = (x+i)*8 + (y+i); if (ps[g] == 1) return 0;}
}
}
// knight
if (c == 'A' || c == 'C' || c == 'M') {
if (valid(x-1, y-2)) {int g = (x-1)*8 + (y-2); if (ps[g] == 1) return 0;}
if (valid(x+1, y-2)) {int g = (x+1)*8 + (y-2); if (ps[g] == 1) return 0;}
if (valid(x-1, y+2)) {int g = (x-1)*8 + (y+2); if (ps[g] == 1) return 0;}
if (valid(x+1, y+2)) {int g = (x+1)*8 + (y+2); if (ps[g] == 1) return 0;}
if (valid(x-2, y-1)) {int g = (x-2)*8 + (y-1); if (ps[g] == 1) return 0;}
if (valid(x+2, y-1)) {int g = (x+2)*8 + (y-1); if (ps[g] == 1) return 0;}
if (valid(x-2, y+1)) {int g = (x-2)*8 + (y+1); if (ps[g] == 1) return 0;}
if (valid(x+2, y+1)) {int g = (x+2)*8 + (y+1); if (ps[g] == 1) return 0;}
}
return 1;
}
bool go(string &s, int i, bitset<64> bs, bitset<64> ps) {
if (i == 12) return 0;
for (int j = 0; j < 64; j++) {
if (!bs[j] && check_attack(ps, s[i], j)) {
bitset<64> nx1 = fill(bs, s[i], j);
bitset<64> nx2 = ps; nx2[j] = 1;
if (!go(s, i+1, nx1, nx2)) {
return 1;
}
}
}
return 0;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
string s; cin >> s;
bitset<64> bs;
if (go(s, 0, bs, bs)) {
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: 85ms
memory: 3384kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 6ms
memory: 3388kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3420kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 12ms
memory: 3424kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 4ms
memory: 3500kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: 0
Accepted
time: 5ms
memory: 3420kb
input:
MRCMABRQCQAB
output:
Alice
result:
ok single line: 'Alice'
Test #7:
score: 0
Accepted
time: 11ms
memory: 3424kb
input:
BBRCMMQAAQRC
output:
Alice
result:
ok single line: 'Alice'
Test #8:
score: 0
Accepted
time: 8ms
memory: 3420kb
input:
RRMCQMACABQB
output:
Alice
result:
ok single line: 'Alice'
Test #9:
score: 0
Accepted
time: 4ms
memory: 3516kb
input:
QMQBMRBACACR
output:
Alice
result:
ok single line: 'Alice'
Test #10:
score: 0
Accepted
time: 5ms
memory: 3380kb
input:
CMRQAQCBBRAM
output:
Alice
result:
ok single line: 'Alice'
Test #11:
score: 0
Accepted
time: 16ms
memory: 3460kb
input:
CABCRQMMRQAB
output:
Alice
result:
ok single line: 'Alice'
Test #12:
score: 0
Accepted
time: 38ms
memory: 3424kb
input:
ARCBBCMQRAQM
output:
Alice
result:
ok single line: 'Alice'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
ARCMCARMQBBQ
output:
Alice
result:
ok single line: 'Alice'
Test #14:
score: 0
Accepted
time: 26ms
memory: 3416kb
input:
AQABMCQCMRRB
output:
Bob
result:
ok single line: 'Bob'
Test #15:
score: 0
Accepted
time: 6ms
memory: 3396kb
input:
ACMRABRQMCBQ
output:
Alice
result:
ok single line: 'Alice'
Test #16:
score: 0
Accepted
time: 28ms
memory: 3436kb
input:
CBARMBCQMQAR
output:
Bob
result:
ok single line: 'Bob'
Test #17:
score: 0
Accepted
time: 44ms
memory: 3500kb
input:
RBABRQMCAMQC
output:
Bob
result:
ok single line: 'Bob'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
MBCQBQARRMCA
output:
Alice
result:
ok single line: 'Alice'
Test #19:
score: 0
Accepted
time: 17ms
memory: 3384kb
input:
AMBQRBCQACMR
output:
Bob
result:
ok single line: 'Bob'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
QRAMQMBBCRAC
output:
Alice
result:
ok single line: 'Alice'
Test #21:
score: 0
Accepted
time: 3ms
memory: 3472kb
input:
ARBCQMMBARQC
output:
Alice
result:
ok single line: 'Alice'
Test #22:
score: 0
Accepted
time: 63ms
memory: 3388kb
input:
CACAMBRQQRBM
output:
Bob
result:
ok single line: 'Bob'
Test #23:
score: 0
Accepted
time: 31ms
memory: 3520kb
input:
CQRRMMBQABCA
output:
Bob
result:
ok single line: 'Bob'
Test #24:
score: 0
Accepted
time: 29ms
memory: 3460kb
input:
ABABCQRMMCRQ
output:
Alice
result:
ok single line: 'Alice'
Test #25:
score: 0
Accepted
time: 11ms
memory: 3468kb
input:
CMBRAAQRQMBC
output:
Bob
result:
ok single line: 'Bob'
Test #26:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
AQBMRMQRBACC
output:
Alice
result:
ok single line: 'Alice'
Test #27:
score: 0
Accepted
time: 14ms
memory: 3416kb
input:
BRACQQMCAMBR
output:
Bob
result:
ok single line: 'Bob'
Test #28:
score: 0
Accepted
time: 5ms
memory: 3428kb
input:
MCCAQBMQRABR
output:
Bob
result:
ok single line: 'Bob'
Test #29:
score: 0
Accepted
time: 29ms
memory: 3440kb
input:
RBQBCRAACMQM
output:
Bob
result:
ok single line: 'Bob'
Test #30:
score: 0
Accepted
time: 11ms
memory: 3388kb
input:
ACRQARMBBQMC
output:
Bob
result:
ok single line: 'Bob'
Test #31:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
MRCQBCBQRMAA
output:
Alice
result:
ok single line: 'Alice'
Test #32:
score: 0
Accepted
time: 12ms
memory: 3384kb
input:
ACRQQCMMBBAR
output:
Bob
result:
ok single line: 'Bob'
Test #33:
score: 0
Accepted
time: 6ms
memory: 3440kb
input:
MMACQBRQABRC
output:
Bob
result:
ok single line: 'Bob'
Test #34:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
QACMQABRMCBR
output:
Alice
result:
ok single line: 'Alice'
Test #35:
score: 0
Accepted
time: 10ms
memory: 3444kb
input:
ACAQRCMRMBQB
output:
Alice
result:
ok single line: 'Alice'
Test #36:
score: 0
Accepted
time: 20ms
memory: 3364kb
input:
RABQCQMCABMR
output:
Bob
result:
ok single line: 'Bob'
Test #37:
score: 0
Accepted
time: 7ms
memory: 3384kb
input:
QQBARCRBMMAC
output:
Alice
result:
ok single line: 'Alice'
Test #38:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
RQMRQABCABCM
output:
Alice
result:
ok single line: 'Alice'
Test #39:
score: 0
Accepted
time: 4ms
memory: 3468kb
input:
RQAMBRQCCBMA
output:
Alice
result:
ok single line: 'Alice'
Test #40:
score: 0
Accepted
time: 3ms
memory: 3396kb
input:
QQBACMARMRBC
output:
Alice
result:
ok single line: 'Alice'
Test #41:
score: 0
Accepted
time: 9ms
memory: 3444kb
input:
QAQCRRAMMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #42:
score: 0
Accepted
time: 7ms
memory: 3504kb
input:
QQBMCBRARMAC
output:
Bob
result:
ok single line: 'Bob'
Test #43:
score: 0
Accepted
time: 113ms
memory: 3444kb
input:
BABARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #44:
score: 0
Accepted
time: 518ms
memory: 3424kb
input:
BBARARCCQQMM
output:
Alice
result:
ok single line: 'Alice'
Test #45:
score: 0
Accepted
time: 44ms
memory: 3468kb
input:
BBAARCRCQQMM
output:
Alice
result:
ok single line: 'Alice'
Test #46:
score: 0
Accepted
time: 136ms
memory: 3396kb
input:
BBAARRCQCQMM
output:
Bob
result:
ok single line: 'Bob'
Test #47:
score: 0
Accepted
time: 86ms
memory: 3412kb
input:
BBAARRCCQMQM
output:
Bob
result:
ok single line: 'Bob'
Test #48:
score: 0
Accepted
time: 300ms
memory: 3404kb
input:
BBAACCRQMQRM
output:
Bob
result:
ok single line: 'Bob'
Test #49:
score: 0
Accepted
time: 317ms
memory: 3504kb
input:
BACBACQRRQMM
output:
Bob
result:
ok single line: 'Bob'
Test #50:
score: 0
Accepted
time: 922ms
memory: 3400kb
input:
RAABBRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #51:
score: 0
Accepted
time: 77ms
memory: 3488kb
input:
RABRBQMCACQM
output:
Bob
result:
ok single line: 'Bob'
Test #52:
score: 0
Accepted
time: 1ms
memory: 3416kb
input:
CMMQQABCRABR
output:
Alice
result:
ok single line: 'Alice'
Test #53:
score: 0
Accepted
time: 177ms
memory: 3504kb
input:
RBAABRCCQQMM
output:
Alice
result:
ok single line: 'Alice'
Extra Test:
score: 0
Extra Test Passed