QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#231881#7635. Fairy ChesszhouhuanyiWA 78ms3552kbC++231.7kb2023-10-29 17:35:042023-10-29 17:35:04

Judging History

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

  • [2023-10-29 17:35:04]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:3552kb
  • [2023-10-29 17:35:04]
  • 提交

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=='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=='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]]+=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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 78ms
memory: 3512kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

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

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: -100
Wrong Answer
time: 45ms
memory: 3552kb

input:

QQRAACMRMCBB

output:

Bob

result:

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