QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506535 | #7635. Fairy Chess | pandapythoner# | TL | 0ms | 0kb | C++23 | 3.6kb | 2024-08-05 19:04:34 | 2024-08-05 19:04:35 |
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) {
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;
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: 0
Time Limit Exceeded
input:
BBAARRCCQQMM