QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#229771 | #7635. Fairy Chess | ucup-team1516# | WA | 368ms | 40524kb | C++17 | 3.7kb | 2023-10-28 16:52:38 | 2023-10-28 16:52:38 |
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);
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);
}
if (i+j == k+l or i-j == k-l) {
ka[id] |= bit(nid);
}
if (abs(k-i) == 1 and abs(j-l) == 2) {
ke[id] |= bit(nid);
}
if (abs(k-i) == 2 and abs(j-l) == 1) {
ke[id] |= bit(nid);
}
}
}
}
}
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;
map<vector<pair<int,int>>,bool> mp;
auto slv = [&](auto slv, vector<pair<int,int>> v, int i) -> bool {
if (mp.find(v) != mp.end()) {
return mp[v];
}
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');
for (auto &[j,k] : v) {
vector<pair<int,int>> nv;
// 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) continue;
// nvの更新
ull ng = 0;
int id = cid(j, k);
if (hisya) ng |= hi[id];
if (kaku) ng |= ka[id];
if (keima) ng |= ke[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, i+1);
pre.pop_back();
if (!res) {
mp[v] = true;
return true;
}
}
mp[v] = false;
return false;
};
if (slv(slv, init, 0)) {
cout << "Alice" << endl;
}
else {
cout << "Bob" << endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 368ms
memory: 40524kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 20ms
memory: 5752kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 7ms
memory: 4732kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 36ms
memory: 8172kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 10ms
memory: 4632kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: -100
Wrong Answer
time: 39ms
memory: 7788kb
input:
MRCMABRQCQAB
output:
Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'