QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232571#7635. Fairy Chessmendicillin2#TL 553ms40304kbC++173.2kb2023-10-30 16:41:342023-10-30 16:41:34

Judging History

你现在查看的是最新测评结果

  • [2023-10-30 16:41:34]
  • 评测
  • 测评结果:TL
  • 用时:553ms
  • 内存:40304kb
  • [2023-10-30 16:41:34]
  • 提交

answer

//#pragma GCC optimize ("Ofast")
#include <bits/extc++.h>
using namespace std;

using ll = int64_t;
using ull = uint64_t;

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

namespace hash_map_impl {

struct custom_hash {
	static const uint64_t c = ll(4e18 * acos(0)) + 71;
	const ll z = mt();
	ll operator ()(ll x) const { return __builtin_bswap64((x ^ z) * c); }
};

template <class K, class V>
using hash_map = __gnu_pbds::gp_hash_table<K, V, custom_hash>;

} // namespace hash_map_impl

namespace hashing_impl {

struct H {
	ull x;
	H(ull x_ = 0) : x(x_) {}
#define OP(O,A,B) H operator O(H o) { ull r = x; asm \
	(A "addq %%rdx, %0\n adcq $0,%0" : "+a"(r) : B); return r; }
	OP(+,,"d"(o.x)) OP(*,"mul %1\n", "r"(o.x) : "rdx")
	H operator - (H o) { return *this + H(~o.x); }
	explicit operator ull() const { return x + !~x; }
	bool operator == (H o) const { return ull(*this) == ull(o); }
	bool operator < (H o) const { return ull(*this) < ull(o); }
};

H rand_base() {
	return H(2 * uniform_int_distribution<ll>(4e10, 5e10)(mt) + 1);
}

} // namespace hashing_impl

bool can_attack(char type, int x, int y, int ox, int oy) {
	if (type == 'B') {
		return x+y == ox+oy || x-y == ox-oy;
	} else if (type == 'R') {
		return x == ox || y == oy;
	} else if (type == 'Q') {
		return can_attack('B', x, y, ox, oy)
			|| can_attack('R', x, y, ox, oy);
	} else if (type == 'K') {
		return (x - ox) * (x - ox) + (y - oy) * (y - oy) == 5;
	} else if (type == 'C') {
		return can_attack('R', x, y, ox, oy)
			|| can_attack('K', x, y, ox, oy);
	} else if (type == 'M') {
		return can_attack('Q', x, y, ox, oy)
			|| can_attack('K', x, y, ox, oy);
	} else if (type == 'A') {
		return can_attack('B', x, y, ox, oy)
			|| can_attack('K', x, y, ox, oy);
	} assert(false);
}

bool works_pair(char t, int x, int y, char ot, int ox, int oy) {
	if (x == ox && y == oy) return false;
	return !(can_attack(t, x, y, ox, oy)
			 || can_attack(ot, ox, oy, x, y));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	string A; cin >> A;
	constexpr int L = 12;
	assert(int(A.size()) == L);

	using C = array<int, 2>;
	using S = array<C, L>;
	using hashing_impl::H;
	const H base = hashing_impl::rand_base();

	using T = ull;
	auto encode = [&](int cur, const S& s) -> T {
		H v = 0;
		for (int i = 0; i < cur; i++) {
			v = v * base + H(9 * (s[i][0]+1) + (s[i][1]+1));
		}
		return ull(v);
	};

	using hash_map_impl::hash_map;
	hash_map<ull, bool> mem;
	//map<T, bool> mem;
	auto wins = [&](auto self, int cur, S locs) -> bool {
		if (cur == L) return false;
		T encoded = encode(cur, locs);
		auto it = mem.find(encoded);
		if (it == mem.end()) {
			bool res = [&]() -> bool {
				for (int x = 0; x < 8; x++) {
					for (int y = 0; y < 8; y++) {
						if ([&]() -> bool {
							for (int j = 0; j < cur; j++) {
								if (!works_pair(A[cur], x, y,
											   A[j], locs[j][0], locs[j][1])) {
									return false;
								}
							}
							return true;
						}()) {
							locs[cur] = {x, y};
							if (!self(self, cur+1, locs)) {
								return true;
							}
						} else {
							// do nothing
						}
					}
				}
				return false;
			}();
			it = mem.insert({encoded, res}).first;
		}
		return it->second;
	};
	cout << (wins(wins, 0, S{}) ? "Alice" : "Bob") << '\n';

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 432ms
memory: 40200kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 32ms
memory: 5620kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: 0
Accepted
time: 18ms
memory: 4348kb

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

score: 0
Accepted
time: 59ms
memory: 8048kb

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

score: 0
Accepted
time: 17ms
memory: 4484kb

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

score: 0
Accepted
time: 35ms
memory: 5516kb

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

score: 0
Accepted
time: 67ms
memory: 7892kb

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

score: 0
Accepted
time: 69ms
memory: 8008kb

input:

RRMCQMACABQB

output:

Alice

result:

ok single line: 'Alice'

Test #9:

score: 0
Accepted
time: 68ms
memory: 7892kb

input:

QMQBMRBACACR

output:

Alice

result:

ok single line: 'Alice'

Test #10:

score: 0
Accepted
time: 30ms
memory: 5588kb

input:

CMRQAQCBBRAM

output:

Alice

result:

ok single line: 'Alice'

Test #11:

score: 0
Accepted
time: 74ms
memory: 7940kb

input:

CABCRQMMRQAB

output:

Alice

result:

ok single line: 'Alice'

Test #12:

score: 0
Accepted
time: 192ms
memory: 21836kb

input:

ARCBBCMQRAQM

output:

Alice

result:

ok single line: 'Alice'

Test #13:

score: 0
Accepted
time: 9ms
memory: 3888kb

input:

ARCMCARMQBBQ

output:

Alice

result:

ok single line: 'Alice'

Test #14:

score: 0
Accepted
time: 136ms
memory: 12520kb

input:

AQABMCQCMRRB

output:

Bob

result:

ok single line: 'Bob'

Test #15:

score: 0
Accepted
time: 32ms
memory: 5724kb

input:

ACMRABRQMCBQ

output:

Alice

result:

ok single line: 'Alice'

Test #16:

score: 0
Accepted
time: 141ms
memory: 12536kb

input:

CBARMBCQMQAR

output:

Bob

result:

ok single line: 'Bob'

Test #17:

score: 0
Accepted
time: 178ms
memory: 12520kb

input:

RBABRQMCAMQC

output:

Bob

result:

ok single line: 'Bob'

Test #18:

score: 0
Accepted
time: 11ms
memory: 3872kb

input:

MBCQBQARRMCA

output:

Alice

result:

ok single line: 'Alice'

Test #19:

score: 0
Accepted
time: 113ms
memory: 12596kb

input:

AMBQRBCQACMR

output:

Bob

result:

ok single line: 'Bob'

Test #20:

score: 0
Accepted
time: 3ms
memory: 3920kb

input:

QRAMQMBBCRAC

output:

Alice

result:

ok single line: 'Alice'

Test #21:

score: 0
Accepted
time: 24ms
memory: 4396kb

input:

ARBCQMMBARQC

output:

Alice

result:

ok single line: 'Alice'

Test #22:

score: 0
Accepted
time: 342ms
memory: 40260kb

input:

CACAMBRQQRBM

output:

Bob

result:

ok single line: 'Bob'

Test #23:

score: 0
Accepted
time: 157ms
memory: 12528kb

input:

CQRRMMBQABCA

output:

Bob

result:

ok single line: 'Bob'

Test #24:

score: 0
Accepted
time: 135ms
memory: 12468kb

input:

ABABCQRMMCRQ

output:

Alice

result:

ok single line: 'Alice'

Test #25:

score: 0
Accepted
time: 65ms
memory: 8056kb

input:

CMBRAAQRQMBC

output:

Bob

result:

ok single line: 'Bob'

Test #26:

score: 0
Accepted
time: 10ms
memory: 3796kb

input:

AQBMRMQRBACC

output:

Alice

result:

ok single line: 'Alice'

Test #27:

score: 0
Accepted
time: 80ms
memory: 7848kb

input:

BRACQQMCAMBR

output:

Bob

result:

ok single line: 'Bob'

Test #28:

score: 0
Accepted
time: 30ms
memory: 5552kb

input:

MCCAQBMQRABR

output:

Bob

result:

ok single line: 'Bob'

Test #29:

score: 0
Accepted
time: 150ms
memory: 12548kb

input:

RBQBCRAACMQM

output:

Bob

result:

ok single line: 'Bob'

Test #30:

score: 0
Accepted
time: 64ms
memory: 7880kb

input:

ACRQARMBBQMC

output:

Bob

result:

ok single line: 'Bob'

Test #31:

score: 0
Accepted
time: 8ms
memory: 3888kb

input:

MRCQBCBQRMAA

output:

Alice

result:

ok single line: 'Alice'

Test #32:

score: 0
Accepted
time: 68ms
memory: 7840kb

input:

ACRQQCMMBBAR

output:

Bob

result:

ok single line: 'Bob'

Test #33:

score: 0
Accepted
time: 38ms
memory: 5556kb

input:

MMACQBRQABRC

output:

Bob

result:

ok single line: 'Bob'

Test #34:

score: 0
Accepted
time: 13ms
memory: 4500kb

input:

QACMQABRMCBR

output:

Alice

result:

ok single line: 'Alice'

Test #35:

score: 0
Accepted
time: 56ms
memory: 8004kb

input:

ACAQRCMRMBQB

output:

Alice

result:

ok single line: 'Alice'

Test #36:

score: 0
Accepted
time: 77ms
memory: 7864kb

input:

RABQCQMCABMR

output:

Bob

result:

ok single line: 'Bob'

Test #37:

score: 0
Accepted
time: 42ms
memory: 7936kb

input:

QQBARCRBMMAC

output:

Alice

result:

ok single line: 'Alice'

Test #38:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

RQMRQABCABCM

output:

Alice

result:

ok single line: 'Alice'

Test #39:

score: 0
Accepted
time: 18ms
memory: 4500kb

input:

RQAMBRQCCBMA

output:

Alice

result:

ok single line: 'Alice'

Test #40:

score: 0
Accepted
time: 10ms
memory: 3952kb

input:

QQBACMARMRBC

output:

Alice

result:

ok single line: 'Alice'

Test #41:

score: 0
Accepted
time: 69ms
memory: 8052kb

input:

QAQCRRAMMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #42:

score: 0
Accepted
time: 44ms
memory: 7856kb

input:

QQBMCBRARMAC

output:

Bob

result:

ok single line: 'Bob'

Test #43:

score: 0
Accepted
time: 553ms
memory: 40304kb

input:

BABARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #44:

score: -100
Time Limit Exceeded

input:

BBARARCCQQMM

output:


result: