QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#231891#7635. Fairy ChesszhouhuanyiAC ✓674ms3696kbC++231.7kb2023-10-29 17:42:502023-10-29 17:42:51

Judging History

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

  • [2023-10-29 17:42:51]
  • 评测
  • 测评结果:AC
  • 用时:674ms
  • 内存:3696kb
  • [2023-10-29 17:42:50]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 8
using namespace std;
int sx[N+1]={0,1,2,-1,-2,1,2,-1,-2},sy[N+1]={0,2,1,-2,-1,-2,-1,2,1},cnt[N+1][N+1];
string s;
char c[N+1][N+1];
bool check(int x,int y,char d)
{
	if (d=='R'||d=='Q'||d=='C'||d=='M')
	{
		for (int i=1;i<=8;++i)
		{
			if (i!=y&&c[x][i]!='.') return 0;
			if (i!=x&&c[i][y]!='.') return 0;
		}
	}
	if (d=='B'||d=='Q'||d=='A'||d=='M')
	{
		for (int i=1;i<=8;++i)
			if (i!=x)
			{
				if (y-abs(x-i)>=1&&c[i][y-abs(x-i)]!='.') return 0;
				if (y+abs(x-i)<=8&&c[i][y+abs(x-i)]!='.') return 0;
			}
	}
	if (d=='C'||d=='A'||d=='M')
	{
		for (int i=1;i<=8;++i)
			if (1<=x+sx[i]&&x+sx[i]<=8&&1<=y+sy[i]&&y+sy[i]<=8&&c[x+sx[i]][y+sy[i]]!='.')
				return 0;
	}
	return 1;
}
void get(int x,int y,char d,int ds)
{
	if (d=='R'||d=='Q'||d=='C'||d=='M')
	{
		for (int i=1;i<=8;++i)
		{
			if (i!=y) cnt[x][i]+=ds;
			if (i!=x) cnt[i][y]+=ds;
		}
	}
	if (d=='B'||d=='Q'||d=='A'||d=='M')
	{
		for (int i=1;i<=8;++i)
			if (i!=x)
			{
				if (y-abs(x-i)>=1) cnt[i][y-abs(x-i)]+=ds;
				if (y+abs(x-i)<=8) cnt[i][y+abs(x-i)]+=ds;
			}
	}
	if (d=='C'||d=='A'||d=='M')
	{
		for (int i=1;i<=8;++i)
			if (1<=x+sx[i]&&x+sx[i]<=8&&1<=y+sy[i]&&y+sy[i]<=8)
				cnt[x+sx[i]][y+sy[i]]+=ds;
	}
	return;
}
bool dfs(int x)
{
	bool op=0;
	for (int i=1;i<=8;++i)
		for (int j=1;j<=8;++j)
			if (c[i][j]=='.'&&!cnt[i][j]&&check(i,j,s[x]))
			{
				c[i][j]=s[x],get(i,j,s[x],1),op|=(!dfs(x+1)),get(i,j,s[x],-1),c[i][j]='.';
				if (op) return 1;
			}
	return op;
}
int main()
{
	for (int i=1;i<=8;++i)
		for (int j=1;j<=8;++j)
			c[i][j]='.';
	cin>>s,puts(dfs(0)?"Alice":"Bob");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 61ms
memory: 3640kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

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

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

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

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

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

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

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

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

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

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

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

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

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

input:

RRMCQMACABQB

output:

Alice

result:

ok single line: 'Alice'

Test #9:

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

input:

QMQBMRBACACR

output:

Alice

result:

ok single line: 'Alice'

Test #10:

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

input:

CMRQAQCBBRAM

output:

Alice

result:

ok single line: 'Alice'

Test #11:

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

input:

CABCRQMMRQAB

output:

Alice

result:

ok single line: 'Alice'

Test #12:

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

input:

ARCBBCMQRAQM

output:

Alice

result:

ok single line: 'Alice'

Test #13:

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

input:

ARCMCARMQBBQ

output:

Alice

result:

ok single line: 'Alice'

Test #14:

score: 0
Accepted
time: 23ms
memory: 3680kb

input:

AQABMCQCMRRB

output:

Bob

result:

ok single line: 'Bob'

Test #15:

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

input:

ACMRABRQMCBQ

output:

Alice

result:

ok single line: 'Alice'

Test #16:

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

input:

CBARMBCQMQAR

output:

Bob

result:

ok single line: 'Bob'

Test #17:

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

input:

RBABRQMCAMQC

output:

Bob

result:

ok single line: 'Bob'

Test #18:

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

input:

MBCQBQARRMCA

output:

Alice

result:

ok single line: 'Alice'

Test #19:

score: 0
Accepted
time: 15ms
memory: 3504kb

input:

AMBQRBCQACMR

output:

Bob

result:

ok single line: 'Bob'

Test #20:

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

input:

QRAMQMBBCRAC

output:

Alice

result:

ok single line: 'Alice'

Test #21:

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

input:

ARBCQMMBARQC

output:

Alice

result:

ok single line: 'Alice'

Test #22:

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

input:

CACAMBRQQRBM

output:

Bob

result:

ok single line: 'Bob'

Test #23:

score: 0
Accepted
time: 23ms
memory: 3500kb

input:

CQRRMMBQABCA

output:

Bob

result:

ok single line: 'Bob'

Test #24:

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

input:

ABABCQRMMCRQ

output:

Alice

result:

ok single line: 'Alice'

Test #25:

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

input:

CMBRAAQRQMBC

output:

Bob

result:

ok single line: 'Bob'

Test #26:

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

input:

AQBMRMQRBACC

output:

Alice

result:

ok single line: 'Alice'

Test #27:

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

input:

BRACQQMCAMBR

output:

Bob

result:

ok single line: 'Bob'

Test #28:

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

input:

MCCAQBMQRABR

output:

Bob

result:

ok single line: 'Bob'

Test #29:

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

input:

RBQBCRAACMQM

output:

Bob

result:

ok single line: 'Bob'

Test #30:

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

input:

ACRQARMBBQMC

output:

Bob

result:

ok single line: 'Bob'

Test #31:

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

input:

MRCQBCBQRMAA

output:

Alice

result:

ok single line: 'Alice'

Test #32:

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

input:

ACRQQCMMBBAR

output:

Bob

result:

ok single line: 'Bob'

Test #33:

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

input:

MMACQBRQABRC

output:

Bob

result:

ok single line: 'Bob'

Test #34:

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

input:

QACMQABRMCBR

output:

Alice

result:

ok single line: 'Alice'

Test #35:

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

input:

ACAQRCMRMBQB

output:

Alice

result:

ok single line: 'Alice'

Test #36:

score: 0
Accepted
time: 15ms
memory: 3680kb

input:

RABQCQMCABMR

output:

Bob

result:

ok single line: 'Bob'

Test #37:

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

input:

QQBARCRBMMAC

output:

Alice

result:

ok single line: 'Alice'

Test #38:

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

input:

RQMRQABCABCM

output:

Alice

result:

ok single line: 'Alice'

Test #39:

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

input:

RQAMBRQCCBMA

output:

Alice

result:

ok single line: 'Alice'

Test #40:

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

input:

QQBACMARMRBC

output:

Alice

result:

ok single line: 'Alice'

Test #41:

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

input:

QAQCRRAMMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #42:

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

input:

QQBMCBRARMAC

output:

Bob

result:

ok single line: 'Bob'

Test #43:

score: 0
Accepted
time: 78ms
memory: 3684kb

input:

BABARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #44:

score: 0
Accepted
time: 394ms
memory: 3640kb

input:

BBARARCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #45:

score: 0
Accepted
time: 33ms
memory: 3520kb

input:

BBAARCRCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #46:

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

input:

BBAARRCQCQMM

output:

Bob

result:

ok single line: 'Bob'

Test #47:

score: 0
Accepted
time: 60ms
memory: 3692kb

input:

BBAARRCCQMQM

output:

Bob

result:

ok single line: 'Bob'

Test #48:

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

input:

BBAACCRQMQRM

output:

Bob

result:

ok single line: 'Bob'

Test #49:

score: 0
Accepted
time: 268ms
memory: 3688kb

input:

BACBACQRRQMM

output:

Bob

result:

ok single line: 'Bob'

Test #50:

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

input:

RAABBRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #51:

score: 0
Accepted
time: 52ms
memory: 3500kb

input:

RABRBQMCACQM

output:

Bob

result:

ok single line: 'Bob'

Test #52:

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

input:

CMMQQABCRABR

output:

Alice

result:

ok single line: 'Alice'

Test #53:

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

input:

RBAABRCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Extra Test:

score: 0
Extra Test Passed