QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#230197 | #7635. Fairy Chess | ucup-team1516# | WA | 608ms | 52228kb | C++17 | 4.4kb | 2023-10-28 17:51:23 | 2023-10-28 17:51:24 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
ull bit(int x) {
return ((ull)1 << x);
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
auto cid = [&](int x, int y) -> int {
return x*8+y;
};
vector<ull> hi(64),ka(64),ke(64);
vector<ull> ihi(64),ika(64),ike(64);
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
int id = cid(i,j);
for (int k = 0; k < 8; ++k) {
for (int l = 0; l < 8; ++l) {
int nid = cid(k,l);
if (k == i or j == l) {
hi[id] |= bit(nid);
ihi[nid] |= bit(id);
}
if (i+j == k+l or i-j == k-l) {
ka[id] |= bit(nid);
ika[nid] |= bit(id);
}
if (abs(k-i) == 1 and abs(j-l) == 2) {
ke[id] |= bit(nid);
ike[nid] |= bit(id);
}
if (abs(k-i) == 2 and abs(j-l) == 1) {
ke[id] |= bit(nid);
ike[nid] |= bit(id);
}
}
}
}
}
vector<pair<int,int>> init(64);
for (int i = 0; i < 64; ++i) {
init[i] = {i/8, i%8};
}
string str = "BBAARRCCQQMM";
cin >> str;
vector<pair<int,int>> pre;
using V = vector<pair<int,int>>;
map<pair<V,tuple<ull,ull,ull>>,bool> mp;
auto slv = [&](auto slv, vector<pair<int,int>> v, ull n1, ull n2, ull n3, int i) -> bool {
char c = str[i];
bool hisya = (c == 'R' or c == 'Q' or c == 'C' or c == 'M');
bool kaku = (c == 'B' or c == 'Q' or c == 'A' or c == 'M');
bool keima = (c == 'A' or c == 'C' or c == 'M');
ull okeru = 0;
V can;
for (auto &[j,k] : v) {
okeru |= bit(cid(j,k));
// preを攻撃しないか
bool ok = true;
for (auto &[l, m] : pre) {
if (hisya) {
if (j == l or k == m) {
ok = false;
break;
}
}
if (kaku) {
if (j+k == l+m or j-k == l-m) {
ok = false;
break;
}
}
if (keima) {
int u1 = abs(j-l);
int u2 = abs(k-m);
if (u1 > u2) swap(u1, u2);
if (u1 == 1 and u2 == 2) {
ok = false;
break;
}
}
}
if (ok) {
can.push_back({j,k});
}
}
n1 &= okeru;
n2 &= okeru;
n3 &= okeru;
if (mp.find({v,{n1,n2,n3}}) != mp.end()) {
return mp[{v,{n1,n2,n3}}];
}
for (auto &[j,k] : can) {
vector<pair<int,int>> nv;
// nvの更新
ull ng = 0;
int id = cid(j, k);
if (hisya) {
ng |= hi[id];
n1 |= ihi[id];
}
if (kaku) {
ng |= ka[id];
n2 |= ika[id];
}
if (keima) {
ng |= ke[id];
n3 |= ike[id];
}
for (auto &[l, m] : v) {
if (ng&bit(cid(l,m))) continue;
nv.push_back({l,m});
}
pre.push_back({j, k});
auto res = slv(slv, nv, n1, n2, n3, i+1);
pre.pop_back();
if (!res) {
mp[{v,{n1,n2,n3}}] = true;
return true;
}
}
mp[{v,{n1,n2,n3}}] = false;
return false;
};
if (slv(slv, init, 0, 0, 0, 0)) {
cout << "Alice" << endl;
}
else {
cout << "Bob" << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 608ms
memory: 52228kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 31ms
memory: 6672kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 16ms
memory: 5064kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 66ms
memory: 9216kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: -100
Wrong Answer
time: 141ms
memory: 15972kb
input:
ACQCMQRBBRMA
output:
Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'