QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#18142 | #2213. Knight | Wu_Ren# | WA | 89ms | 29668kb | C++11 | 1.1kb | 2022-01-16 15:15:06 | 2022-05-04 17:11:55 |
Judging History
answer
#include<bits/stdc++.h>
int mod;
#define id(a,b) (((a)-1)*m+(b))
using namespace std;
int n,m,K,alice,bob,r,c;
int head[1000010],o=0,cnt=0,vis[1000010];
char s[1010][1010];
struct edge{
int to,link;
}e[8000010];
void add_edge(int u,int v){
e[++o]=(edge){v,head[u]},head[u]=o;
e[++o]=(edge){u,head[v]},head[v]=o;
}
void dfs(int u,int c){
vis[u]=c;
for(int i=head[u];i;i=e[i].link) if(!vis[e[i].to]) dfs(e[i].to,-c);
}
int main(){
scanf("%d%d%d%d",&n,&m,&r,&c);
int fx[][2]={{r,c},{r,-c},{c,r},{c,-r}};
for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i][j]!='@'){
for(int k=0;k<4;k++){
int x=i+fx[k][0],y=j+fx[k][1];
if(1<=x&&x<=n&&1<=y&&y<=m&&s[x][y]!='@') if(id(i,j)!=id(x,y)) add_edge(id(i,j),id(x,y));
}
}
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(!vis[id(i,j)]){
if(s[i][j]=='A'||s[i][j]=='B') dfs(id(i,j),++cnt);
if(s[i][j]=='A') alice=id(i,j);
if(s[i][j]=='B') bob=id(i,j);
}
if(!head[alice]) puts("Bob"),exit(0);
if(abs(vis[alice])!=abs(vis[bob])||vis[alice]==vis[bob]) puts("Alice");
else puts("Bob");
}
详细
Test #1:
score: 100
Accepted
time: 12ms
memory: 19952kb
Test #2:
score: 0
Accepted
time: 5ms
memory: 9936kb
Test #3:
score: 0
Accepted
time: 89ms
memory: 29668kb
Test #4:
score: -100
Wrong Answer
time: 29ms
memory: 22496kb