QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#236149 | #7635. Fairy Chess | ucup-team956# | WA | 1ms | 3588kb | C++20 | 2.4kb | 2023-11-03 17:12:00 | 2023-11-03 17:12:01 |
Judging History
answer
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
#define ull unsigned long long
string s;
map<ull,int> mp[20];
int in(ull S,int bit) {return (S>>bit)&1;}
int pd(int x,int y) {return 0<=x and x<8 and 0<=y and y<8;}
void ban_car(ull &S,int x,int y) {
FOR(i,0,7) S|=1ull<<(i*8+y);
FOR(i,0,7) S|=1ull<<(x*8+i);
}
void ban_xiang(ull &S,int x,int y) {
FOR(i,0,7) if(pd(i,x+y-i)) S|=1ull<<(i*8+x+y-i);
FOR(i,0,7) if(pd(i,y-x+i)) S|=1ull<<(i*8+y-x+i);
}
void ban_horse(ull &S,int x,int y) {
for(auto i:{-2,2}) for(auto j:{-1,1}) {
if(pd(x+i,y+j)) S|=1ull<<((x+i)*8+(y+j));
if(pd(x+j,y+i)) S|=1ull<<((x+j)*8+(y+i));
}
}
void get_car(ull &tot,ull S,int x,int y) {
FOR(i,0,7) tot+=in(S,(i*8+y));
FOR(i,0,7) tot+=in(S,(x*8+i));
}
void get_xiang(ull &tot,ull S,int x,int y) {
FOR(i,0,7) if(pd(i,x+y-i)) tot+=in(S,(i*8+x+y-i));
FOR(i,0,7) if(pd(i,y-x+i)) tot+=in(S,(i*8+y-x+i));
}
void get_horse(ull &tot,ull S,int x,int y) {
for(auto i:{-2,2}) for(auto j:{-1,1}) {
if(pd(x+i,y+j)) tot+=in(S,((x+i)*8+(y+j)));
if(pd(x+j,y+i)) tot+=in(S,((x+j)*8+(y+i)));
}
}
void debug(ull S) {
FOR(i,0,7) {
FOR(j,0,7) cout<<in(S,i*8+j);
cout<<"\n";
}cout<<"\n";
}
int sg(ull S,int now) {
if(mp[now].count(S)) return mp[now][S];
FOR(i,0,7) FOR(j,0,7) if(in(S,i*8+j)==0) {
ull T=S|(1ull<<(i*8+j)),tot=0;
if(s[now]=='B') get_xiang(tot,S,i,j);
if(s[now]=='R') get_car(tot,S,i,j);
if(s[now]=='Q') get_car(tot,S,i,j), get_xiang(tot,S,i,j);
if(s[now]=='A') get_xiang(tot,S,i,j),get_horse(tot,S,i,j);
if(s[now]=='C') get_car(tot,S,i,j), get_horse(tot,S,i,j);
if(s[now]=='M') get_car(tot,S,i,j), get_xiang(tot,S,i,j),get_horse(tot,S,i,j);
if(tot) continue;
if(s[now]=='B') ban_xiang(T,i,j);
if(s[now]=='R') ban_car(T,i,j);
if(s[now]=='Q') ban_car(T,i,j), ban_xiang(T,i,j);
if(s[now]=='A') ban_xiang(T,i,j),ban_horse(T,i,j);
if(s[now]=='C') ban_car(T,i,j), ban_horse(T,i,j);
if(s[now]=='M') ban_car(T,i,j), ban_xiang(T,i,j),ban_horse(T,i,j);
if(sg(T,now+1)==0) return mp[now][S]=1,1;
}
return mp[now][S]=0,0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin>>s;
if(sg(0,0)) cout<<"Alice\n";
else cout<<"Bob\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3332kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3420kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
MRCMABRQCQAB
output:
Alice
result:
ok single line: 'Alice'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3420kb
input:
BBRCMMQAAQRC
output:
Bob
result:
wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'