QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#18140 | #2213. Knight | Realityang# | WA | 35ms | 18972kb | C++14 | 1.4kb | 2022-01-16 15:02:59 | 2022-05-04 17:11:49 |
Judging History
answer
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1010,mod=1e9+7;
int n,vis[N][N],ri[N][N],m,r,c,ax,ay,bx,by;
int fx[9][2]={{-1,-1},{-1,1},{1,-1},{1,1},{-1,-1},{-1,1},{1,-1},{1,1}};
bool ac(int x,int y){
if(x<1||y<1||x>n||y>m||ri[x][y]||vis[x][y])return false;
return true;
}
void dfs(int x,int y,int co,int ad){
vis[x][y]=co;
for(int i=0;i<8;i++){
int xx=x+fx[i][0],yy=y+fx[i][1];
if(!ac(xx,yy))continue;
if(!ad)dfs(xx,yy,co+1,1);
else dfs(xx,yy,co-1,0);
}
}
void A(){printf("Alice");exit(0);}
void B(){printf("Bob");exit(0);}
signed main(){
scanf("%d%d%d%d",&n,&m,&r,&c);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char s=getchar();while(s!='A'&&s!='B'&&s!='.'&&s!='@')s=getchar();
if(s=='A')ax=i,ay=j;
if(s=='B')bx=i,by=j;
if(s=='@')ri[i][j]=1;
}
}int colo=1;
for(int i=0;i<4;i++)fx[i][0]*=r,fx[i][1]*=c;
for(int i=4;i<8;i++)fx[i][1]*=r,fx[i][0]*=c;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(vis[i][j]||ri[i][j])continue;
vis[i][j]=++colo;
dfs(i,j,colo,0);
colo++;
}
}
int rt=0;
for(int i=0;i<8;i++){
int xx=ax+fx[i][0],yy=ay+fx[i][1];
if(xx<1||yy<1||xx>n||yy>m||ri[xx][yy]||(xx==bx&&yy==by)||(xx==ax&&yy==ay))continue;
rt=1;
}
if(!rt)B();
if(vis[ax][ay]/2!=vis[bx][by]/2)A();
if(vis[ax][ay]==vis[bx][by])B();
else A();
}
/*
3 3 2 1
.A@
B..
@..
*/
Details
Test #1:
score: 100
Accepted
time: 15ms
memory: 10296kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 6440kb
Test #3:
score: 0
Accepted
time: 35ms
memory: 18972kb
Test #4:
score: -100
Wrong Answer
time: 30ms
memory: 16516kb