QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#231883#7635. Fairy ChesszhouhuanyiWA 64ms3556kbC++231.7kb2023-10-29 17:36:032023-10-29 17:36:04

Judging History

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

  • [2023-10-29 17:36:04]
  • 评测
  • 测评结果:WA
  • 用时:64ms
  • 内存:3556kb
  • [2023-10-29 17:36:03]
  • 提交

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=='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: 64ms
memory: 3556kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

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

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: -100
Wrong Answer
time: 43ms
memory: 3264kb

input:

QQRAACMRMCBB

output:

Bob

result:

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