QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#241817 | #7635. Fairy Chess | SolitaryDream# | RE | 1ms | 3824kb | C++17 | 1.9kb | 2023-11-06 17:58:30 | 2023-11-06 17:58:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
int dx[]={-1,-2,-2,-1,1,2,2,1},dy[]={2,1,-1,-2,-2,-1,1,2};
ull rook[64],bishop[64],knight[64];
char s[15];
map<tuple<int,ull,ull>,int> rem;
int dfs(int x,ull p,ull a)
{
if(x==13)
return 0;
if(rem.count({x,p,a}))
return rem[{x,p,a}];
auto &ret=rem[{x,p,a}];
for(int i=0;i<64;i++)
{
if((p>>i&1)||(a>>i&1))
continue;
ull atk;
if(s[x]=='B')
atk=bishop[i];
else if(s[x]=='R')
atk=rook[i];
else if(s[x]=='K')
atk=knight[i];
else if(s[x]=='Q')
atk=rook[i]|bishop[i];
else if(s[x]=='A')
atk=bishop[i]|knight[i];
else if(s[x]=='M')
atk=rook[i]|knight[i];
else
assert(0);
if(atk&p)
continue;
ret|=!dfs(x+1,p|atk,a|1ull<<i);
}
return ret;
}
int gid(int x,int y)
{
if(x<0||x>7||y<0||y>7)
return -1;
return x<<3|y;
}
int main()
{
for(int i=0;i<64;i++)
{
int x=i>>3,y=i&7;
for(int u=-8;u<=8;u++)
{
int p=gid(x+u,y);
if(p!=-1)
rook[i]|=1ull<<p;
p=gid(x,y+u);
if(p!=-1)
rook[i]|=1ull<<p;
}
for(int u=-8;u<=8;u++)
{
int p=gid(x+u,y+u);
if(p!=-1)
bishop[i]|=1ull<<p;
p=gid(x-u,y+u);
if(p!=-1)
bishop[i]|=1ull<<p;
}
for(int u=0;u<8;u++)
{
int p=gid(x+dx[u],y+dy[u]);
if(p!=-1)
knight[i]|=1ull<<p;
}
}
scanf("%s",s+1);
if(dfs(1,0,0))
puts("Alice");
else
puts("Bob");
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3764kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: -100
Runtime Error
input:
ACQCMQRBBRMA