QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#231871#7635. Fairy ChesszhouhuanyiWA 1ms3568kbC++231.6kb2023-10-29 17:26:402023-10-29 17:26:41

Judging History

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

  • [2023-10-29 17:26:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3568kb
  • [2023-10-29 17:26:40]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 8
using namespace std;
int sx[N+1]={1,2,-1,-2,1,2,-1,-2},sy[N+1]={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=='M')
	{
		for (int i=1;i<=8;++i)
		{
			if (c[x][i]!='.') return 0;
			if (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=='K'||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=='M')
	{
		for (int i=1;i<=8;++i)
		{
			if (i!=y) cnt[x][i]++;
			if (i!=x) cnt[i][y]++;
		}
	}
	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)]++;
				if (y+abs(x-i)<=8) cnt[i][y+abs(x-i)]++;
			}
	}
	if (d=='K'||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]]++;
	}
	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]='.';
	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: 1ms
memory: 3512kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

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

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

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

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

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

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

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

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

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

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

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

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

score: -100
Wrong Answer
time: 1ms
memory: 3516kb

input:

RRMCQMACABQB

output:

Bob

result:

wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'