QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#230544#7635. Fairy Chessucup-team2303#TL 936ms54888kbC++173.4kb2023-10-28 19:27:552023-10-28 19:28:11

Judging History

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

  • [2023-10-28 19:28:11]
  • 评测
  • 测评结果:TL
  • 用时:936ms
  • 内存:54888kb
  • [2023-10-28 19:27:55]
  • 提交

answer

// #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define PB emplace_back
// #define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) {rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1];}

char s[15];
int p[9][9], dx[8] = {-2, -1, 1, 2, 2, 1, -1, -2}, dy[8] = {-1, -2, -2, -1, 1, 2, 2, 1}, t[9][9];
#define ull unsigned long long
#define MP make_pair
map<pair<ull, ull>, bool> mp[13];

inline bool R(int n, int m, int k) {
	bool o = 1;
	for(int x = n - 1, y = m - 1; x && y; --x, --y) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	for(int x = n + 1, y = m - 1; x <= 8 && y; ++x, --y) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	for(int x = n - 1, y = m + 1; x && y <= 8; --x, ++y) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	for(int x = n + 1, y = m + 1; x <= 8 && y <= 8; ++x, ++y) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	return o;
}
inline bool G(int n, int m, int k) {
	bool o = 1;
	for(int x = n - 1, y = m; x; --x) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	for(int x = n + 1, y = m; x <= 8; ++x) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	for(int x = n, y = m - 1; y; --y) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	for(int x = n, y = m + 1; y <= 8; ++y) {
		p[x][y] += k;
		o &= !t[x][y];
	}
	return o;
}
inline bool B(int n, int m, int k) {
	bool o = 1;
	rep(i, 0, 7) {
		int x = n + dx[i], y = m + dy[i];
		if(x >= 1 && x <= 8 && y >= 1 && y <= 8) {
			p[x][y] += k;
			o &= !t[x][y];
		}
	}
	return o;
}
inline bool ins(int n, int m, char o, int k) {
	p[n][m] += k;
	t[n][m] += k;
	bool q = 1;
	if(o == 'B') q = R(n, m, k);
	else if(o == 'R') q = G(n, m, k);
	else if(o == 'Q') q = R(n, m, k) & G(n, m, k);
	else if(o == 'A') q = R(n, m, k) & B(n, m, k);
	else if(o == 'C') q = G(n, m, k) & B(n, m, k);
	else if(o == 'M') q = R(n, m, k) & G(n, m, k) & B(n, m, k);
	if(!q) {
		// cout << p[n][m] << ' ' << ' ' << t[n][m] << ' ' << k << endl;
		p[n][m] -= k, t[n][m] -= k;
		if(o == 'B') R(n, m, -k);
		else if(o == 'R') G(n, m, -k);
		else if(o == 'Q') R(n, m, -k), G(n, m, -k);
		else if(o == 'A') R(n, m, -k), B(n, m, -k);
		else if(o == 'C') G(n, m, -k), B(n, m, -k);
		else if(o == 'M') R(n, m, -k), G(n, m, -k), B(n, m, -k);
	}
	return q;
}
bool dfs(int n) {
	if(n > 12) return 0;
	ull sp = 0;
	rep(i, 1, 8) rep(j, 1, 8) sp |= ((ull) (!p[i][j])) << ((i - 1) * 8 + j - 1);
	ull sq = 0;
	rep(i, 1, 8) rep(j, 1, 8) sq |= ((ull) (t[i][j])) << ((i - 1) * 8 + j - 1);
	if(!sp) return 0;
	if(mp[n].count(MP(sp, sq))) return mp[n][MP(sp, sq)];
	rep(i, 1, 8) rep(j, 1, 8) if(!p[i][j]) {
		if(ins(i, j, s[n], 1)) {
			if(!dfs(n + 1)) {
				ins(i, j, s[n], -1);
				return mp[n][MP(sp, sq)] = 1;
			}
			ins(i, j, s[n], -1);
		}
		// cout << n << ' ' << i << ' ' << j << endl;
		// if(n == 1) rep(i, 1, 8) rep(j, 1, 8) cout << p[i][j] << " \n"[j == 8];
	}
	return mp[n][MP(sp, sq)] = 0;
}

signed main() {
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> s + 1;
	dfs(1) ? cout << "Alice" : cout << "Bob";
	return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 220ms
memory: 18148kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

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

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

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

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

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

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

score: 0
Accepted
time: 6ms
memory: 4440kb

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

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

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

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

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

score: 0
Accepted
time: 16ms
memory: 5704kb

input:

RRMCQMACABQB

output:

Alice

result:

ok single line: 'Alice'

Test #9:

score: 0
Accepted
time: 19ms
memory: 5780kb

input:

QMQBMRBACACR

output:

Alice

result:

ok single line: 'Alice'

Test #10:

score: 0
Accepted
time: 12ms
memory: 5020kb

input:

CMRQAQCBBRAM

output:

Alice

result:

ok single line: 'Alice'

Test #11:

score: 0
Accepted
time: 40ms
memory: 6552kb

input:

CABCRQMMRQAB

output:

Alice

result:

ok single line: 'Alice'

Test #12:

score: 0
Accepted
time: 101ms
memory: 10044kb

input:

ARCBBCMQRAQM

output:

Alice

result:

ok single line: 'Alice'

Test #13:

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

input:

ARCMCARMQBBQ

output:

Alice

result:

ok single line: 'Alice'

Test #14:

score: 0
Accepted
time: 61ms
memory: 8340kb

input:

AQABMCQCMRRB

output:

Bob

result:

ok single line: 'Bob'

Test #15:

score: 0
Accepted
time: 6ms
memory: 5040kb

input:

ACMRABRQMCBQ

output:

Alice

result:

ok single line: 'Alice'

Test #16:

score: 0
Accepted
time: 75ms
memory: 9664kb

input:

CBARMBCQMQAR

output:

Bob

result:

ok single line: 'Bob'

Test #17:

score: 0
Accepted
time: 111ms
memory: 10296kb

input:

RBABRQMCAMQC

output:

Bob

result:

ok single line: 'Bob'

Test #18:

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

input:

MBCQBQARRMCA

output:

Alice

result:

ok single line: 'Alice'

Test #19:

score: 0
Accepted
time: 40ms
memory: 7656kb

input:

AMBQRBCQACMR

output:

Bob

result:

ok single line: 'Bob'

Test #20:

score: 0
Accepted
time: 1ms
memory: 4028kb

input:

QRAMQMBBCRAC

output:

Alice

result:

ok single line: 'Alice'

Test #21:

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

input:

ARBCQMMBARQC

output:

Alice

result:

ok single line: 'Alice'

Test #22:

score: 0
Accepted
time: 146ms
memory: 14712kb

input:

CACAMBRQQRBM

output:

Bob

result:

ok single line: 'Bob'

Test #23:

score: 0
Accepted
time: 50ms
memory: 7900kb

input:

CQRRMMBQABCA

output:

Bob

result:

ok single line: 'Bob'

Test #24:

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

input:

ABABCQRMMCRQ

output:

Alice

result:

ok single line: 'Alice'

Test #25:

score: 0
Accepted
time: 29ms
memory: 6292kb

input:

CMBRAAQRQMBC

output:

Bob

result:

ok single line: 'Bob'

Test #26:

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

input:

AQBMRMQRBACC

output:

Alice

result:

ok single line: 'Alice'

Test #27:

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

input:

BRACQQMCAMBR

output:

Bob

result:

ok single line: 'Bob'

Test #28:

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

input:

MCCAQBMQRABR

output:

Bob

result:

ok single line: 'Bob'

Test #29:

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

input:

RBQBCRAACMQM

output:

Bob

result:

ok single line: 'Bob'

Test #30:

score: 0
Accepted
time: 22ms
memory: 5892kb

input:

ACRQARMBBQMC

output:

Bob

result:

ok single line: 'Bob'

Test #31:

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

input:

MRCQBCBQRMAA

output:

Alice

result:

ok single line: 'Alice'

Test #32:

score: 0
Accepted
time: 26ms
memory: 6132kb

input:

ACRQQCMMBBAR

output:

Bob

result:

ok single line: 'Bob'

Test #33:

score: 0
Accepted
time: 14ms
memory: 5264kb

input:

MMACQBRQABRC

output:

Bob

result:

ok single line: 'Bob'

Test #34:

score: 0
Accepted
time: 5ms
memory: 4440kb

input:

QACMQABRMCBR

output:

Alice

result:

ok single line: 'Alice'

Test #35:

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

input:

ACAQRCMRMBQB

output:

Alice

result:

ok single line: 'Alice'

Test #36:

score: 0
Accepted
time: 48ms
memory: 6936kb

input:

RABQCQMCABMR

output:

Bob

result:

ok single line: 'Bob'

Test #37:

score: 0
Accepted
time: 19ms
memory: 5528kb

input:

QQBARCRBMMAC

output:

Alice

result:

ok single line: 'Alice'

Test #38:

score: 0
Accepted
time: 2ms
memory: 4092kb

input:

RQMRQABCABCM

output:

Alice

result:

ok single line: 'Alice'

Test #39:

score: 0
Accepted
time: 6ms
memory: 4764kb

input:

RQAMBRQCCBMA

output:

Alice

result:

ok single line: 'Alice'

Test #40:

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

input:

QQBACMARMRBC

output:

Alice

result:

ok single line: 'Alice'

Test #41:

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

input:

QAQCRRAMMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #42:

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

input:

QQBMCBRARMAC

output:

Bob

result:

ok single line: 'Bob'

Test #43:

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

input:

BABARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #44:

score: 0
Accepted
time: 936ms
memory: 51996kb

input:

BBARARCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #45:

score: 0
Accepted
time: 99ms
memory: 10732kb

input:

BBAARCRCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #46:

score: 0
Accepted
time: 306ms
memory: 21944kb

input:

BBAARRCQCQMM

output:

Bob

result:

ok single line: 'Bob'

Test #47:

score: 0
Accepted
time: 227ms
memory: 18144kb

input:

BBAARRCCQMQM

output:

Bob

result:

ok single line: 'Bob'

Test #48:

score: 0
Accepted
time: 709ms
memory: 42244kb

input:

BBAACCRQMQRM

output:

Bob

result:

ok single line: 'Bob'

Test #49:

score: 0
Accepted
time: 928ms
memory: 54888kb

input:

BACBACQRRQMM

output:

Bob

result:

ok single line: 'Bob'

Test #50:

score: -100
Time Limit Exceeded

input:

RAABBRCCQQMM

output:

Bob

result: