QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#241820 | #7635. Fairy Chess | SolitaryDream# | WA | 1ms | 3828kb | C++17 | 1.9kb | 2023-11-06 18:00:34 | 2023-11-06 18:00:35 |
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]=='C')
atk=rook[i]|knight[i];
else if(s[x]=='M')
atk=knight[i]|rook[i]|bishop[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: 0ms
memory: 3820kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
MRCMABRQCQAB
output:
Alice
result:
ok single line: 'Alice'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3756kb
input:
BBRCMMQAAQRC
output:
Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'