QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#229658 | #7635. Fairy Chess | ucup-team1055# | WA | 0ms | 3744kb | C++20 | 4.2kb | 2023-10-28 16:37:49 | 2023-10-28 16:37:49 |
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) -> bool {
if (i % 2 == 0){
bool res = false;
rep(x,0,8){
rep(y,0,8){
if (b & board[a[i]][x][y]) continue;
if (sfs(sfs,i+1,b | 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 (b & board[a[i]][x][y]) continue;
if (!sfs(sfs,i+1,b | board[a[i]][x][y])){
res = true;
break;
}
}
if (res) break;
}
return !res;
}
};
bool ans = dfs(dfs,0,0);
cout << (ans ? "Alice" : "Bob") << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3744kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
MRCMABRQCQAB
output:
Alice
result:
ok single line: 'Alice'
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3552kb
input:
BBRCMMQAAQRC
output:
Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'