QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#230093 | #7635. Fairy Chess | ucup-team1191# | WA | 27ms | 9884kb | C++23 | 5.1kb | 2023-10-28 17:37:26 | 2023-10-28 17:37:26 |
Judging History
answer
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
enum class Piece {
BISHOP,
ROOK,
QUEEN,
ARCHBISHOP,
CHANCELLOR,
MAHARAJAH,
KNIGHT,
};
const int N = 8;
const int K = 6;
ull mask_cover[N][N][K + 1];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
auto valid = [&](int x, int y) { return 0 <= x && x < N && 0 <= y && y < N; };
auto add = [&](int i, int j, int x, int y, Piece k) {
if (valid(x, y)) {
mask_cover[i][j][(int)k] |= 1ULL << (x * N + y);
}
};
{ // knight
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
add(i, j, i, j, Piece::KNIGHT);
add(i, j, i + 1, j + 2, Piece::KNIGHT);
add(i, j, i + 1, j - 2, Piece::KNIGHT);
add(i, j, i - 1, j + 2, Piece::KNIGHT);
add(i, j, i - 1, j - 2, Piece::KNIGHT);
add(i, j, i + 2, j + 1, Piece::KNIGHT);
add(i, j, i + 2, j - 1, Piece::KNIGHT);
add(i, j, i - 2, j + 1, Piece::KNIGHT);
add(i, j, i - 2, j - 1, Piece::KNIGHT);
}
}
}
{ // bishop
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
for (int t = 0; t < 3 * N; ++t) {
add(i, j, i + t, j + t, Piece::BISHOP);
add(i, j, i + t, j - t, Piece::BISHOP);
add(i, j, i - t, j + t, Piece::BISHOP);
add(i, j, i - t, j - t, Piece::BISHOP);
}
}
}
}
{ // rook
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
for (int t = 0; t < 3 * N; ++t) {
add(i, j, i + t, j, Piece::ROOK);
add(i, j, i - t, j, Piece::ROOK);
add(i, j, i, j + t, Piece::ROOK);
add(i, j, i, j - t, Piece::ROOK);
}
}
}
}
{ // queen
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
mask_cover[i][j][(int)Piece::QUEEN] =
mask_cover[i][j][(int)Piece::BISHOP] |
mask_cover[i][j][(int)Piece::ROOK];
}
}
}
{ // archibishop
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
mask_cover[i][j][(int)Piece::ARCHBISHOP] =
mask_cover[i][j][(int)Piece::BISHOP] |
mask_cover[i][j][(int)Piece::KNIGHT];
}
}
}
{ // chancellor
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
mask_cover[i][j][(int)Piece::CHANCELLOR] =
mask_cover[i][j][(int)Piece::ROOK] |
mask_cover[i][j][(int)Piece::KNIGHT];
}
}
}
{ // maharajah
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
mask_cover[i][j][(int)Piece::MAHARAJAH] =
mask_cover[i][j][(int)Piece::QUEEN] |
mask_cover[i][j][(int)Piece::KNIGHT];
}
}
}
vector<int> order(2 * K);
for (int i = 0; i < 2 * K; ++i) {
char c;
cin >> c;
if (c == 'B') {
order[i] = (int)Piece::BISHOP;
} else if (c == 'R') {
order[i] = (int)Piece::ROOK;
} else if (c == 'Q') {
order[i] = (int)Piece::QUEEN;
} else if (c == 'A') {
order[i] = (int)Piece::ARCHBISHOP;
} else if (c == 'C') {
order[i] = (int)Piece::CHANCELLOR;
} else if (c == 'M') {
order[i] = (int)Piece::MAHARAJAH;
} else {
assert(false);
}
}
/*for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cout << ((mask_cover[3][3][(int)Piece::MAHARAJAH] >> (N * i + j)) & 1);
}
cout << '\n';
}
return 0;*/
mt19937_64 rnd(123);
ull mask_pieces = 0;
ull mask_covered = 0;
ull mask_mult = rnd();
int ptr = 0;
unordered_map<ull, bool> mem;
function<bool()> rec = [&]() {
ull hash_pos = mask_covered * mask_mult + ptr;
if (mem.count(hash_pos)) {
return mem[hash_pos];
}
if (ptr == 2 * K) {
mem[hash_pos] = false;
return false;
}
ull mask_covered_anti = ~mask_covered;
while (mask_covered_anti > 0) {
int b = __builtin_ctzll(mask_covered_anti);
mask_covered_anti &= ~(1ULL << b);
int i = b / N;
int j = b % N;
int p = order[ptr];
if (mask_pieces & mask_cover[i][j][p]) {
continue;
}
ull sf_covered = mask_covered;
mask_pieces |= (1ULL << (i * N + j));
mask_covered |= mask_cover[i][j][p];
++ptr;
auto res = rec();
--ptr;
mask_pieces &= ~(1ULL << (i * N + j));
mask_covered = sf_covered;
if (!res) {
mem[hash_pos] = true;
return true;
}
}
mem[hash_pos] = false;
return false;
};
cout << (rec() ? "Alice" : "Bob") << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 27ms
memory: 9884kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 2ms
memory: 4032kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 3ms
memory: 4216kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4028kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: -100
Wrong Answer
time: 8ms
memory: 5604kb
input:
MRCMABRQCQAB
output:
Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'