QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#229303#7635. Fairy Chessucup-team266#AC ✓429ms3828kbC++143.6kb2023-10-28 15:44:182023-10-28 15:44:18

Judging History

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

  • [2023-10-28 15:44:18]
  • 评测
  • 测评结果:AC
  • 用时:429ms
  • 内存:3828kb
  • [2023-10-28 15:44:18]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const int inv2 = (Mod+1) / 2;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 111;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
	pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
	invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(ll &a, ll b){ (b>a) ? (a=b) : 0; }
inline void chmin(ll &a, ll b){ (b<a) ? (a=b) : 0; }

string s;
ull ban = 0, has = 0;

ull pos[3][8][8];

inline int id(int a, int b){ return a*8 + b; }
bool dfs(int p){
	//if(p <= 2){
	//	cout << "dfs " << p << endl;
	//	rep(x, 8) rep(y, 8){
	//		cout << ((ban >> id(x, y)) & 1) << (y != 7 ? ' ' : '\n');
	//	}
	//}
	if(p >= 12 || __builtin_popcountll(ban) >= 64) return 0;
	rep(i, 8) rep(j, 8){
		if(!((ban >> id(i, j)) & 1)){
			ull cur = 0;
			if(s[p] == 'B' || s[p] == 'Q' || s[p] == 'A' || s[p] == 'M') cur |= pos[0][i][j];
			if(s[p] == 'R' || s[p] == 'Q' || s[p] == 'C' || s[p] == 'M') cur |= pos[1][i][j];
			if(s[p] == 'A' || s[p] == 'C' || s[p] == 'M') cur |= pos[2][i][j];
			if(cur & has) continue;
			//if(p <= 1) cout << i << " " << j << "\n";
			//rep(x, 8) rep(y, 8){
			//	cout << ((cur >> id(x, y)) & 1) << (y != 7 ? ' ' : '\n');
			//}
			cur |= ban, swap(ban, cur), has ^= 1ull << id(i, j);
			bool can = dfs(p+1);
			swap(cur, ban), has ^= 1ull << id(i, j);
			if(!can) return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	rep(i, 8) rep(j, 8){
		ull &cur = pos[0][i][j];
		auto ad = [&](int x, int y){
			if(x >= 0 && x < 8 && y >= 0 && y < 8) cur |= (1ull << id(x, y));
		};
		rep(x, 8){
			ad(i-x, j-x), ad(i-x, j+x), ad(i+x, j-x), ad(i+x, j+x);
		}
		//cout << i << " " << j << ": " << "\n";
		//rep(x, 8) rep(y, 8){
		//	cout << ((cur >> id(x, y)) & 1) << (y != 7 ? ' ' : '\n');
		//}
	}

	rep(i, 8) rep(j, 8){
		ull &cur = pos[1][i][j];
		auto ad = [&](int x, int y){
			if(x >= 0 && x < 8 && y >= 0 && y < 8) cur |= (1ull << id(x, y));
		};
		rep(x, 8){
			ad(i-x, j), ad(i, j-x), ad(i+x, j), ad(i, j+x);
		}
	}

	rep(i, 8) rep(j, 8){
		ull &cur = pos[2][i][j];
		auto ad = [&](int x, int y){
			if(x >= 0 && x < 8 && y >= 0 && y < 8) cur |= (1ull << id(x, y));
		};
		ad(i-2, j-1), ad(i-2, j+1), ad(i+2, j-1), ad(i+2, j+1);
		ad(i-1, j-2), ad(i-1, j+2), ad(i+1, j-2), ad(i+1, j+2);
		ad(i, j);
	}

	cin >> s;
	cout << (dfs(0) ? "Alice" : "Bob") << "\n";

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 42ms
memory: 3532kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

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

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

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

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

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

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

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

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

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

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

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

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

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

input:

RRMCQMACABQB

output:

Alice

result:

ok single line: 'Alice'

Test #9:

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

input:

QMQBMRBACACR

output:

Alice

result:

ok single line: 'Alice'

Test #10:

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

input:

CMRQAQCBBRAM

output:

Alice

result:

ok single line: 'Alice'

Test #11:

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

input:

CABCRQMMRQAB

output:

Alice

result:

ok single line: 'Alice'

Test #12:

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

input:

ARCBBCMQRAQM

output:

Alice

result:

ok single line: 'Alice'

Test #13:

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

input:

ARCMCARMQBBQ

output:

Alice

result:

ok single line: 'Alice'

Test #14:

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

input:

AQABMCQCMRRB

output:

Bob

result:

ok single line: 'Bob'

Test #15:

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

input:

ACMRABRQMCBQ

output:

Alice

result:

ok single line: 'Alice'

Test #16:

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

input:

CBARMBCQMQAR

output:

Bob

result:

ok single line: 'Bob'

Test #17:

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

input:

RBABRQMCAMQC

output:

Bob

result:

ok single line: 'Bob'

Test #18:

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

input:

MBCQBQARRMCA

output:

Alice

result:

ok single line: 'Alice'

Test #19:

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

input:

AMBQRBCQACMR

output:

Bob

result:

ok single line: 'Bob'

Test #20:

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

input:

QRAMQMBBCRAC

output:

Alice

result:

ok single line: 'Alice'

Test #21:

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

input:

ARBCQMMBARQC

output:

Alice

result:

ok single line: 'Alice'

Test #22:

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

input:

CACAMBRQQRBM

output:

Bob

result:

ok single line: 'Bob'

Test #23:

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

input:

CQRRMMBQABCA

output:

Bob

result:

ok single line: 'Bob'

Test #24:

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

input:

ABABCQRMMCRQ

output:

Alice

result:

ok single line: 'Alice'

Test #25:

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

input:

CMBRAAQRQMBC

output:

Bob

result:

ok single line: 'Bob'

Test #26:

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

input:

AQBMRMQRBACC

output:

Alice

result:

ok single line: 'Alice'

Test #27:

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

input:

BRACQQMCAMBR

output:

Bob

result:

ok single line: 'Bob'

Test #28:

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

input:

MCCAQBMQRABR

output:

Bob

result:

ok single line: 'Bob'

Test #29:

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

input:

RBQBCRAACMQM

output:

Bob

result:

ok single line: 'Bob'

Test #30:

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

input:

ACRQARMBBQMC

output:

Bob

result:

ok single line: 'Bob'

Test #31:

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

input:

MRCQBCBQRMAA

output:

Alice

result:

ok single line: 'Alice'

Test #32:

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

input:

ACRQQCMMBBAR

output:

Bob

result:

ok single line: 'Bob'

Test #33:

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

input:

MMACQBRQABRC

output:

Bob

result:

ok single line: 'Bob'

Test #34:

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

input:

QACMQABRMCBR

output:

Alice

result:

ok single line: 'Alice'

Test #35:

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

input:

ACAQRCMRMBQB

output:

Alice

result:

ok single line: 'Alice'

Test #36:

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

input:

RABQCQMCABMR

output:

Bob

result:

ok single line: 'Bob'

Test #37:

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

input:

QQBARCRBMMAC

output:

Alice

result:

ok single line: 'Alice'

Test #38:

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

input:

RQMRQABCABCM

output:

Alice

result:

ok single line: 'Alice'

Test #39:

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

input:

RQAMBRQCCBMA

output:

Alice

result:

ok single line: 'Alice'

Test #40:

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

input:

QQBACMARMRBC

output:

Alice

result:

ok single line: 'Alice'

Test #41:

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

input:

QAQCRRAMMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #42:

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

input:

QQBMCBRARMAC

output:

Bob

result:

ok single line: 'Bob'

Test #43:

score: 0
Accepted
time: 54ms
memory: 3824kb

input:

BABARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #44:

score: 0
Accepted
time: 256ms
memory: 3592kb

input:

BBARARCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #45:

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

input:

BBAARCRCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #46:

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

input:

BBAARRCQCQMM

output:

Bob

result:

ok single line: 'Bob'

Test #47:

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

input:

BBAARRCCQMQM

output:

Bob

result:

ok single line: 'Bob'

Test #48:

score: 0
Accepted
time: 154ms
memory: 3752kb

input:

BBAACCRQMQRM

output:

Bob

result:

ok single line: 'Bob'

Test #49:

score: 0
Accepted
time: 151ms
memory: 3620kb

input:

BACBACQRRQMM

output:

Bob

result:

ok single line: 'Bob'

Test #50:

score: 0
Accepted
time: 429ms
memory: 3532kb

input:

RAABBRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #51:

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

input:

RABRBQMCACQM

output:

Bob

result:

ok single line: 'Bob'

Test #52:

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

input:

CMMQQABCRABR

output:

Alice

result:

ok single line: 'Alice'

Test #53:

score: 0
Accepted
time: 83ms
memory: 3772kb

input:

RBAABRCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Extra Test:

score: 0
Extra Test Passed