QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232289 | #7635. Fairy Chess | neko_nyaa | TL | 0ms | 0kb | C++23 | 2.0kb | 2023-10-30 09:32:19 | 2023-10-30 09:32:19 |
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-1)) {int g = x*8 + (y-i); bs[g] = 1;}
if (valid(x, y+1)) {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 go(string &s, int i, bitset<64> bs) {
//cout << s << ' ' << i << ' ' << bs.to_string() << '\n';
if (i == 12) return 0;
for (int j = 0; j < 64; j++) {
if (!bs[j]) {
bitset<64> nx = fill(bs, s[i], j);
if (!go(s, i+1, nx)) {
return 1;
}
}
}
return 0;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
string s; cin >> s;
bitset<64> bs;
//cout << go(s, 0, bs) << '\n';
if (!go(s, 0, bs)) {
cout << "Alice\n";
} else {
cout << "Bob\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
BBAARRCCQQMM