QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#229979 | #7635. Fairy Chess | ucup-team1448# | AC ✓ | 1038ms | 1540kb | C++17 | 6.4kb | 2023-10-28 17:21:29 | 2023-10-28 17:21:31 |
Judging History
answer
//#define dxx
#ifdef dxx
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dex(a) dbg(#a"=%lld onL%d infun %s\n",a,__LINE__,__FUNCTION__)
#include<cstdlib>
#define pause sys##tem("pause")
#define _GLIBCXX_DEBUG
#endif
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using ll=long long;
using std::max;
using std::min;
using std::abs;
template<class T> void cmax(T&a,T b){a=max(a,b);}
template<class T> void cmin(T&a,T b){a=min(a,b);}
template<class T> T sqr(T a){return a*a;}
namespace xm{
int vis[8][8];
bool plc[8][8];
char seq[15];
constexpr int id(int x,int y){
return x*8+y;
}constexpr bool onb(int x,int y){
return 0<=x&&x<8&&0<=y&&y<8;
}bool dfs(int dep,__int128 S){
if(dep==13){
return 0;
}
for(int i=0;i<8;++i) for(int j=0;j<8;++j) if(!vis[i][j]){
const int dx[]={-2,-2,-1,-1,1,1,2,2};
const int dy[]={-1,1,-2,2,-2,2,-1,1};
auto bishopchk=[&]()->bool{
for(int k=1;k<=i&&k<=j;++k)
if(plc[i-k][j-k]) return 0;;
for(int k=1;k<=i&&j+k<8;++k)
if(plc[i-k][j+k]) return 0;;
for(int k=1;i+k<8&&j+k<8;++k)
if(plc[i+k][j+k]) return 0;;
for(int k=1;i+k<8&&k<=j;++k)
if(plc[i+k][j-k]) return 0;;
return 1;
};
auto bishopapl=[&](){
for(int k=1;k<=i&&k<=j;++k)
if(!vis[i-k][j-k]) vis[i-k][j-k]=dep;
for(int k=1;k<=i&&j+k<8;++k)
if(!vis[i-k][j+k]) vis[i-k][j+k]=dep;
for(int k=1;i+k<8&&j+k<8;++k)
if(!vis[i+k][j+k]) vis[i+k][j+k]=dep;
for(int k=1;i+k<8&&k<=j;++k)
if(!vis[i+k][j-k]) vis[i+k][j-k]=dep;
};
auto bishoprev=[&](){
for(int k=1;k<=i&&k<=j;++k)
if(vis[i-k][j-k]==dep) vis[i-k][j-k]=0;
for(int k=1;k<=i&&j+k<8;++k)
if(vis[i-k][j+k]==dep) vis[i-k][j+k]=0;
for(int k=1;i+k<8&&j+k<8;++k)
if(vis[i+k][j+k]==dep) vis[i+k][j+k]=0;
for(int k=1;i+k<8&&k<=j;++k)
if(vis[i+k][j-k]==dep) vis[i+k][j-k]=0;
};
auto rookchk=[&]()->bool{
for(int k=0;k<8;++k)
if(plc[k][j]) return 0;
for(int k=0;k<8;++k)
if(plc[i][k]) return 0;
return 1;
};
auto rookapl=[&](){
for(int k=0;k<8;++k)
if(!vis[k][j]) vis[k][j]=dep;
for(int k=0;k<8;++k)
if(!vis[i][k]) vis[i][k]=dep;
};
auto rookrev=[&](){
for(int k=0;k<8;++k)
if(vis[k][j]==dep) vis[k][j]=0;
for(int k=0;k<8;++k)
if(vis[i][k]==dep) vis[i][k]=0;
};
auto knichk=[&]()->bool{
for(int d=0;d<8;++d){
int nx=i+dx[d],ny=j+dy[d];
if(onb(nx,ny)&&plc[nx][ny]) return 0;
}
return 1;
};
auto kniapl=[&](){
for(int d=0;d<8;++d){
int nx=i+dx[d],ny=j+dy[d];
if(onb(nx,ny)&&!vis[nx][ny]) vis[nx][ny]=dep;
}
};
auto knirev=[&](){
for(int d=0;d<8;++d){
int nx=i+dx[d],ny=j+dy[d];
if(onb(nx,ny)&&vis[nx][ny]==dep) vis[nx][ny]=0;
}
};
if(seq[dep]=='B'){ //象
bool F=0;
if(!bishopchk()) continue;
bishopapl();
plc[i][j]=vis[i][j]=dep;
if(!dfs(dep+1,S*64+id(i,j))) F=1;
bishoprev();
vis[i][j]=0;
plc[i][j]=0;
if(F) return 1;
}else if(seq[dep]=='R'){ //车
bool F=0;
if(!rookchk()) continue;
rookapl();
plc[i][j]=vis[i][j]=dep;
if(!dfs(dep+1,S*64+id(i,j))) F=1;
rookrev();
vis[i][j]=0;
plc[i][j]=0;
if(F) return 1;
}else if(seq[dep]=='A'){ //象马
bool F=0;
if(!bishopchk()||!knichk()) continue;
bishopapl();
kniapl();
plc[i][j]=vis[i][j]=dep;
if(!dfs(dep+1,S*64+id(i,j))) F=1;
bishoprev();
knirev();
vis[i][j]=0;
plc[i][j]=0;
if(F) return 1;
}else if(seq[dep]=='C'){ //车马
bool F=0;
if(!rookchk()||!knichk()) continue;
rookapl();
kniapl();
plc[i][j]=vis[i][j]=dep;
if(!dfs(dep+1,S*64+id(i,j))) F=1;
rookrev();
knirev();
vis[i][j]=0;
plc[i][j]=0;
if(F) return 1;
}else if(seq[dep]=='Q'){ //后
bool F=0;
if(!rookchk()||!bishopchk()) continue;
rookapl();
bishopapl();
plc[i][j]=vis[i][j]=dep;
if(!dfs(dep+1,S*64+id(i,j))) F=1;
rookrev();
bishoprev();
vis[i][j]=0;
plc[i][j]=0;
if(F) return 1;
}else if(seq[dep]=='M'){ //后马
bool F=0;
if(!rookchk()||!bishopchk()||!knichk()) continue;
rookapl();
bishopapl();
kniapl();
plc[i][j]=vis[i][j]=dep;
if(!dfs(dep+1,S*64+id(i,j))) F=1;
rookrev();
bishoprev();
knirev();
vis[i][j]=0;
plc[i][j]=0;
if(F) return 1;
}
}
return 0;
}void _(){
scanf("%s",seq+1);
if(!dfs(1,0)) puts("Bob");
else puts("Alice");
}
}
int main(){
xm::_();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 88ms
memory: 1504kb
input:
BBAARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #2:
score: 0
Accepted
time: 8ms
memory: 1500kb
input:
BAMBAMQQRCCR
output:
Alice
result:
ok single line: 'Alice'
Test #3:
score: 0
Accepted
time: 4ms
memory: 1348kb
input:
QQRAACMRMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 15ms
memory: 1388kb
input:
MBBARQRMACQC
output:
Alice
result:
ok single line: 'Alice'
Test #5:
score: 0
Accepted
time: 4ms
memory: 1508kb
input:
ACQCMQRBBRMA
output:
Alice
result:
ok single line: 'Alice'
Test #6:
score: 0
Accepted
time: 3ms
memory: 1388kb
input:
MRCMABRQCQAB
output:
Alice
result:
ok single line: 'Alice'
Test #7:
score: 0
Accepted
time: 17ms
memory: 1416kb
input:
BBRCMMQAAQRC
output:
Alice
result:
ok single line: 'Alice'
Test #8:
score: 0
Accepted
time: 10ms
memory: 1340kb
input:
RRMCQMACABQB
output:
Alice
result:
ok single line: 'Alice'
Test #9:
score: 0
Accepted
time: 10ms
memory: 1492kb
input:
QMQBMRBACACR
output:
Alice
result:
ok single line: 'Alice'
Test #10:
score: 0
Accepted
time: 6ms
memory: 1348kb
input:
CMRQAQCBBRAM
output:
Alice
result:
ok single line: 'Alice'
Test #11:
score: 0
Accepted
time: 17ms
memory: 1404kb
input:
CABCRQMMRQAB
output:
Alice
result:
ok single line: 'Alice'
Test #12:
score: 0
Accepted
time: 50ms
memory: 1344kb
input:
ARCBBCMQRAQM
output:
Alice
result:
ok single line: 'Alice'
Test #13:
score: 0
Accepted
time: 2ms
memory: 1496kb
input:
ARCMCARMQBBQ
output:
Alice
result:
ok single line: 'Alice'
Test #14:
score: 0
Accepted
time: 38ms
memory: 1400kb
input:
AQABMCQCMRRB
output:
Bob
result:
ok single line: 'Bob'
Test #15:
score: 0
Accepted
time: 6ms
memory: 1540kb
input:
ACMRABRQMCBQ
output:
Alice
result:
ok single line: 'Alice'
Test #16:
score: 0
Accepted
time: 33ms
memory: 1508kb
input:
CBARMBCQMQAR
output:
Bob
result:
ok single line: 'Bob'
Test #17:
score: 0
Accepted
time: 51ms
memory: 1328kb
input:
RBABRQMCAMQC
output:
Bob
result:
ok single line: 'Bob'
Test #18:
score: 0
Accepted
time: 2ms
memory: 1416kb
input:
MBCQBQARRMCA
output:
Alice
result:
ok single line: 'Alice'
Test #19:
score: 0
Accepted
time: 17ms
memory: 1400kb
input:
AMBQRBCQACMR
output:
Bob
result:
ok single line: 'Bob'
Test #20:
score: 0
Accepted
time: 1ms
memory: 1404kb
input:
QRAMQMBBCRAC
output:
Alice
result:
ok single line: 'Alice'
Test #21:
score: 0
Accepted
time: 6ms
memory: 1388kb
input:
ARBCQMMBARQC
output:
Alice
result:
ok single line: 'Alice'
Test #22:
score: 0
Accepted
time: 73ms
memory: 1452kb
input:
CACAMBRQQRBM
output:
Bob
result:
ok single line: 'Bob'
Test #23:
score: 0
Accepted
time: 32ms
memory: 1352kb
input:
CQRRMMBQABCA
output:
Bob
result:
ok single line: 'Bob'
Test #24:
score: 0
Accepted
time: 41ms
memory: 1472kb
input:
ABABCQRMMCRQ
output:
Alice
result:
ok single line: 'Alice'
Test #25:
score: 0
Accepted
time: 13ms
memory: 1348kb
input:
CMBRAAQRQMBC
output:
Bob
result:
ok single line: 'Bob'
Test #26:
score: 0
Accepted
time: 0ms
memory: 1340kb
input:
AQBMRMQRBACC
output:
Alice
result:
ok single line: 'Alice'
Test #27:
score: 0
Accepted
time: 22ms
memory: 1404kb
input:
BRACQQMCAMBR
output:
Bob
result:
ok single line: 'Bob'
Test #28:
score: 0
Accepted
time: 5ms
memory: 1488kb
input:
MCCAQBMQRABR
output:
Bob
result:
ok single line: 'Bob'
Test #29:
score: 0
Accepted
time: 34ms
memory: 1500kb
input:
RBQBCRAACMQM
output:
Bob
result:
ok single line: 'Bob'
Test #30:
score: 0
Accepted
time: 13ms
memory: 1340kb
input:
ACRQARMBBQMC
output:
Bob
result:
ok single line: 'Bob'
Test #31:
score: 0
Accepted
time: 2ms
memory: 1540kb
input:
MRCQBCBQRMAA
output:
Alice
result:
ok single line: 'Alice'
Test #32:
score: 0
Accepted
time: 14ms
memory: 1344kb
input:
ACRQQCMMBBAR
output:
Bob
result:
ok single line: 'Bob'
Test #33:
score: 0
Accepted
time: 7ms
memory: 1476kb
input:
MMACQBRQABRC
output:
Bob
result:
ok single line: 'Bob'
Test #34:
score: 0
Accepted
time: 2ms
memory: 1400kb
input:
QACMQABRMCBR
output:
Alice
result:
ok single line: 'Alice'
Test #35:
score: 0
Accepted
time: 13ms
memory: 1536kb
input:
ACAQRCMRMBQB
output:
Alice
result:
ok single line: 'Alice'
Test #36:
score: 0
Accepted
time: 22ms
memory: 1344kb
input:
RABQCQMCABMR
output:
Bob
result:
ok single line: 'Bob'
Test #37:
score: 0
Accepted
time: 8ms
memory: 1444kb
input:
QQBARCRBMMAC
output:
Alice
result:
ok single line: 'Alice'
Test #38:
score: 0
Accepted
time: 1ms
memory: 1540kb
input:
RQMRQABCABCM
output:
Alice
result:
ok single line: 'Alice'
Test #39:
score: 0
Accepted
time: 4ms
memory: 1492kb
input:
RQAMBRQCCBMA
output:
Alice
result:
ok single line: 'Alice'
Test #40:
score: 0
Accepted
time: 2ms
memory: 1340kb
input:
QQBACMARMRBC
output:
Alice
result:
ok single line: 'Alice'
Test #41:
score: 0
Accepted
time: 10ms
memory: 1344kb
input:
QAQCRRAMMCBB
output:
Alice
result:
ok single line: 'Alice'
Test #42:
score: 0
Accepted
time: 9ms
memory: 1540kb
input:
QQBMCBRARMAC
output:
Bob
result:
ok single line: 'Bob'
Test #43:
score: 0
Accepted
time: 113ms
memory: 1476kb
input:
BABARRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #44:
score: 0
Accepted
time: 617ms
memory: 1492kb
input:
BBARARCCQQMM
output:
Alice
result:
ok single line: 'Alice'
Test #45:
score: 0
Accepted
time: 52ms
memory: 1340kb
input:
BBAARCRCQQMM
output:
Alice
result:
ok single line: 'Alice'
Test #46:
score: 0
Accepted
time: 157ms
memory: 1500kb
input:
BBAARRCQCQMM
output:
Bob
result:
ok single line: 'Bob'
Test #47:
score: 0
Accepted
time: 89ms
memory: 1508kb
input:
BBAARRCCQMQM
output:
Bob
result:
ok single line: 'Bob'
Test #48:
score: 0
Accepted
time: 378ms
memory: 1348kb
input:
BBAACCRQMQRM
output:
Bob
result:
ok single line: 'Bob'
Test #49:
score: 0
Accepted
time: 414ms
memory: 1492kb
input:
BACBACQRRQMM
output:
Bob
result:
ok single line: 'Bob'
Test #50:
score: 0
Accepted
time: 1038ms
memory: 1396kb
input:
RAABBRCCQQMM
output:
Bob
result:
ok single line: 'Bob'
Test #51:
score: 0
Accepted
time: 87ms
memory: 1388kb
input:
RABRBQMCACQM
output:
Bob
result:
ok single line: 'Bob'
Test #52:
score: 0
Accepted
time: 0ms
memory: 1344kb
input:
CMMQQABCRABR
output:
Alice
result:
ok single line: 'Alice'
Test #53:
score: 0
Accepted
time: 199ms
memory: 1400kb
input:
RBAABRCCQQMM
output:
Alice
result:
ok single line: 'Alice'
Extra Test:
score: 0
Extra Test Passed