QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232572#7635. Fairy Chessmendicillin2#TL 592ms40132kbC++173.2kb2023-10-30 16:42:292023-10-30 16:42:30

Judging History

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

  • [2023-10-30 16:42:30]
  • 评测
  • 测评结果:TL
  • 用时:592ms
  • 内存:40132kb
  • [2023-10-30 16:42:29]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 448ms
memory: 40116kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 36ms
memory: 5572kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

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

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

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

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

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

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

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

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

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

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

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

input:

RRMCQMACABQB

output:

Alice

result:

ok single line: 'Alice'

Test #9:

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

input:

QMQBMRBACACR

output:

Alice

result:

ok single line: 'Alice'

Test #10:

score: 0
Accepted
time: 27ms
memory: 5624kb

input:

CMRQAQCBBRAM

output:

Alice

result:

ok single line: 'Alice'

Test #11:

score: 0
Accepted
time: 72ms
memory: 7876kb

input:

CABCRQMMRQAB

output:

Alice

result:

ok single line: 'Alice'

Test #12:

score: 0
Accepted
time: 190ms
memory: 21748kb

input:

ARCBBCMQRAQM

output:

Alice

result:

ok single line: 'Alice'

Test #13:

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

input:

ARCMCARMQBBQ

output:

Alice

result:

ok single line: 'Alice'

Test #14:

score: 0
Accepted
time: 143ms
memory: 12508kb

input:

AQABMCQCMRRB

output:

Bob

result:

ok single line: 'Bob'

Test #15:

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

input:

ACMRABRQMCBQ

output:

Alice

result:

ok single line: 'Alice'

Test #16:

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

input:

CBARMBCQMQAR

output:

Bob

result:

ok single line: 'Bob'

Test #17:

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

input:

RBABRQMCAMQC

output:

Bob

result:

ok single line: 'Bob'

Test #18:

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

input:

MBCQBQARRMCA

output:

Alice

result:

ok single line: 'Alice'

Test #19:

score: 0
Accepted
time: 114ms
memory: 12516kb

input:

AMBQRBCQACMR

output:

Bob

result:

ok single line: 'Bob'

Test #20:

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

input:

QRAMQMBBCRAC

output:

Alice

result:

ok single line: 'Alice'

Test #21:

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

input:

ARBCQMMBARQC

output:

Alice

result:

ok single line: 'Alice'

Test #22:

score: 0
Accepted
time: 364ms
memory: 40132kb

input:

CACAMBRQQRBM

output:

Bob

result:

ok single line: 'Bob'

Test #23:

score: 0
Accepted
time: 161ms
memory: 12456kb

input:

CQRRMMBQABCA

output:

Bob

result:

ok single line: 'Bob'

Test #24:

score: 0
Accepted
time: 139ms
memory: 12428kb

input:

ABABCQRMMCRQ

output:

Alice

result:

ok single line: 'Alice'

Test #25:

score: 0
Accepted
time: 62ms
memory: 7912kb

input:

CMBRAAQRQMBC

output:

Bob

result:

ok single line: 'Bob'

Test #26:

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

input:

AQBMRMQRBACC

output:

Alice

result:

ok single line: 'Alice'

Test #27:

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

input:

BRACQQMCAMBR

output:

Bob

result:

ok single line: 'Bob'

Test #28:

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

input:

MCCAQBMQRABR

output:

Bob

result:

ok single line: 'Bob'

Test #29:

score: 0
Accepted
time: 162ms
memory: 12448kb

input:

RBQBCRAACMQM

output:

Bob

result:

ok single line: 'Bob'

Test #30:

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

input:

ACRQARMBBQMC

output:

Bob

result:

ok single line: 'Bob'

Test #31:

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

input:

MRCQBCBQRMAA

output:

Alice

result:

ok single line: 'Alice'

Test #32:

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

input:

ACRQQCMMBBAR

output:

Bob

result:

ok single line: 'Bob'

Test #33:

score: 0
Accepted
time: 43ms
memory: 5532kb

input:

MMACQBRQABRC

output:

Bob

result:

ok single line: 'Bob'

Test #34:

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

input:

QACMQABRMCBR

output:

Alice

result:

ok single line: 'Alice'

Test #35:

score: 0
Accepted
time: 57ms
memory: 7952kb

input:

ACAQRCMRMBQB

output:

Alice

result:

ok single line: 'Alice'

Test #36:

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

input:

RABQCQMCABMR

output:

Bob

result:

ok single line: 'Bob'

Test #37:

score: 0
Accepted
time: 43ms
memory: 7876kb

input:

QQBARCRBMMAC

output:

Alice

result:

ok single line: 'Alice'

Test #38:

score: 0
Accepted
time: 4ms
memory: 3916kb

input:

RQMRQABCABCM

output:

Alice

result:

ok single line: 'Alice'

Test #39:

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

input:

RQAMBRQCCBMA

output:

Alice

result:

ok single line: 'Alice'

Test #40:

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

input:

QQBACMARMRBC

output:

Alice

result:

ok single line: 'Alice'

Test #41:

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

input:

QAQCRRAMMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #42:

score: 0
Accepted
time: 53ms
memory: 7860kb

input:

QQBMCBRARMAC

output:

Bob

result:

ok single line: 'Bob'

Test #43:

score: 0
Accepted
time: 592ms
memory: 40104kb

input:

BABARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #44:

score: -100
Time Limit Exceeded

input:

BBARARCCQQMM

output:


result: