QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#231883 | #7635. Fairy Chess | zhouhuanyi | WA | 64ms | 3556kb | C++23 | 1.7kb | 2023-10-29 17:36:03 | 2023-10-29 17:36:04 |
Judging History
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;
}
详细
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'