QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#17922 | #2213. Knight | qingyu_orz | AC ✓ | 809ms | 130788kb | C++14 | 1.3kb | 2022-01-15 12:24:48 | 2022-05-04 16:21:30 |
Judging History
answer
#include<bits/stdc++.h>
#define mk(x,y) ((x-1)*m+y)
using namespace std;
char s[1005][1005];
vector<int>g[1000005];
int mb[8][2];
int col[1000005];
void dfs(int x){
for(auto cu:g[x]){
if(col[cu]){
assert(col[x]+col[cu]==0);
continue;
}
col[cu]=-col[x];
dfs(cu);
}
}
int main(){
int n,m,x,y;
cin>>n>>m>>x>>y;
for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
mb[0][0]=x,mb[0][1]=y;
mb[1][0]=-x,mb[1][1]=y;
mb[2][0]=x,mb[2][1]=-y;
mb[3][0]=-x,mb[3][1]=-y;
mb[4][0]=y,mb[4][1]=x;
mb[5][0]=-y,mb[5][1]=x;
mb[6][0]=y,mb[6][1]=-x;
mb[7][0]=-y,mb[7][1]=-x;
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)
if(s[i][j]!='@'){
for(int k=0;k<8;++k){
int dx=i+mb[k][0],dy=j+mb[k][1];
if(dx<1||dy<1||dx>n||dy>m)continue;
if(s[dx][dy]=='@')continue;
int u=mk(i,j),v=mk(dx,dy);
g[u].emplace_back(v);
g[v].emplace_back(u);
}
}
int A=-1,B=-1;
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j){
if(s[i][j]=='A')A=mk(i,j);
else if(s[i][j]=='B')B=mk(i,j);
}
if(!g[A].size()||g[A][0]==B){
puts("Bob");
return 0;
}
int N=mk(n,m);
for(int i=1;i<=N;++i)if(!col[i]){
col[i]=i;
dfs(i);
}
if(abs(col[A])!=abs(col[B]))puts("Alice");
else if(col[A]==col[B])puts("Alice");
else puts("Bob");
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 55ms
memory: 43668kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 29356kb
Test #3:
score: 0
Accepted
time: 262ms
memory: 61220kb
Test #4:
score: 0
Accepted
time: 117ms
memory: 44620kb
Test #5:
score: 0
Accepted
time: 3ms
memory: 28532kb
Test #6:
score: 0
Accepted
time: 14ms
memory: 32228kb
Test #7:
score: 0
Accepted
time: 8ms
memory: 27456kb
Test #8:
score: 0
Accepted
time: 4ms
memory: 29600kb
Test #9:
score: 0
Accepted
time: 36ms
memory: 38080kb
Test #10:
score: 0
Accepted
time: 20ms
memory: 32900kb
Test #11:
score: 0
Accepted
time: 4ms
memory: 29440kb
Test #12:
score: 0
Accepted
time: 143ms
memory: 51056kb
Test #13:
score: 0
Accepted
time: 26ms
memory: 35868kb
Test #14:
score: 0
Accepted
time: 42ms
memory: 42788kb
Test #15:
score: 0
Accepted
time: 12ms
memory: 33172kb
Test #16:
score: 0
Accepted
time: 7ms
memory: 29212kb
Test #17:
score: 0
Accepted
time: 4ms
memory: 28428kb
Test #18:
score: 0
Accepted
time: 23ms
memory: 31476kb
Test #19:
score: 0
Accepted
time: 10ms
memory: 29528kb
Test #20:
score: 0
Accepted
time: 39ms
memory: 39436kb
Test #21:
score: 0
Accepted
time: 3ms
memory: 28320kb
Test #22:
score: 0
Accepted
time: 9ms
memory: 28584kb
Test #23:
score: 0
Accepted
time: 7ms
memory: 28216kb
Test #24:
score: 0
Accepted
time: 9ms
memory: 29676kb
Test #25:
score: 0
Accepted
time: 12ms
memory: 29068kb
Test #26:
score: 0
Accepted
time: 0ms
memory: 28360kb
Test #27:
score: 0
Accepted
time: 1ms
memory: 28628kb
Test #28:
score: 0
Accepted
time: 192ms
memory: 63956kb
Test #29:
score: 0
Accepted
time: 8ms
memory: 29432kb
Test #30:
score: 0
Accepted
time: 6ms
memory: 33232kb
Test #31:
score: 0
Accepted
time: 15ms
memory: 31784kb
Test #32:
score: 0
Accepted
time: 2ms
memory: 28308kb
Test #33:
score: 0
Accepted
time: 212ms
memory: 55512kb
Test #34:
score: 0
Accepted
time: 10ms
memory: 30112kb
Test #35:
score: 0
Accepted
time: 178ms
memory: 54596kb
Test #36:
score: 0
Accepted
time: 252ms
memory: 55032kb
Test #37:
score: 0
Accepted
time: 14ms
memory: 30036kb
Test #38:
score: 0
Accepted
time: 43ms
memory: 34380kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 29708kb
Test #40:
score: 0
Accepted
time: 4ms
memory: 29404kb
Test #41:
score: 0
Accepted
time: 27ms
memory: 31928kb
Test #42:
score: 0
Accepted
time: 20ms
memory: 33816kb
Test #43:
score: 0
Accepted
time: 28ms
memory: 35844kb
Test #44:
score: 0
Accepted
time: 4ms
memory: 28720kb
Test #45:
score: 0
Accepted
time: 5ms
memory: 28408kb
Test #46:
score: 0
Accepted
time: 4ms
memory: 29296kb
Test #47:
score: 0
Accepted
time: 6ms
memory: 30064kb
Test #48:
score: 0
Accepted
time: 211ms
memory: 49544kb
Test #49:
score: 0
Accepted
time: 39ms
memory: 40352kb
Test #50:
score: 0
Accepted
time: 28ms
memory: 33824kb
Test #51:
score: 0
Accepted
time: 487ms
memory: 76816kb
Test #52:
score: 0
Accepted
time: 462ms
memory: 80440kb
Test #53:
score: 0
Accepted
time: 86ms
memory: 37708kb
Test #54:
score: 0
Accepted
time: 660ms
memory: 111904kb
Test #55:
score: 0
Accepted
time: 313ms
memory: 54204kb
Test #56:
score: 0
Accepted
time: 656ms
memory: 104760kb
Test #57:
score: 0
Accepted
time: 266ms
memory: 53428kb
Test #58:
score: 0
Accepted
time: 32ms
memory: 31676kb
Test #59:
score: 0
Accepted
time: 97ms
memory: 37200kb
Test #60:
score: 0
Accepted
time: 790ms
memory: 108976kb
Test #61:
score: 0
Accepted
time: 222ms
memory: 50840kb
Test #62:
score: 0
Accepted
time: 153ms
memory: 43536kb
Test #63:
score: 0
Accepted
time: 515ms
memory: 81028kb
Test #64:
score: 0
Accepted
time: 92ms
memory: 37532kb
Test #65:
score: 0
Accepted
time: 696ms
memory: 105952kb
Test #66:
score: 0
Accepted
time: 87ms
memory: 37156kb
Test #67:
score: 0
Accepted
time: 383ms
memory: 61508kb
Test #68:
score: 0
Accepted
time: 48ms
memory: 36876kb
Test #69:
score: 0
Accepted
time: 709ms
memory: 114152kb
Test #70:
score: 0
Accepted
time: 189ms
memory: 46128kb
Test #71:
score: 0
Accepted
time: 155ms
memory: 46400kb
Test #72:
score: 0
Accepted
time: 51ms
memory: 35864kb
Test #73:
score: 0
Accepted
time: 82ms
memory: 46788kb
Test #74:
score: 0
Accepted
time: 671ms
memory: 106636kb
Test #75:
score: 0
Accepted
time: 277ms
memory: 58800kb
Test #76:
score: 0
Accepted
time: 387ms
memory: 63280kb
Test #77:
score: 0
Accepted
time: 497ms
memory: 92164kb
Test #78:
score: 0
Accepted
time: 44ms
memory: 35720kb
Test #79:
score: 0
Accepted
time: 93ms
memory: 40372kb
Test #80:
score: 0
Accepted
time: 284ms
memory: 60012kb
Test #81:
score: 0
Accepted
time: 255ms
memory: 57600kb
Test #82:
score: 0
Accepted
time: 258ms
memory: 55384kb
Test #83:
score: 0
Accepted
time: 127ms
memory: 50908kb
Test #84:
score: 0
Accepted
time: 123ms
memory: 42216kb
Test #85:
score: 0
Accepted
time: 81ms
memory: 36708kb
Test #86:
score: 0
Accepted
time: 56ms
memory: 36808kb
Test #87:
score: 0
Accepted
time: 75ms
memory: 40656kb
Test #88:
score: 0
Accepted
time: 50ms
memory: 36824kb
Test #89:
score: 0
Accepted
time: 607ms
memory: 106640kb
Test #90:
score: 0
Accepted
time: 287ms
memory: 55776kb
Test #91:
score: 0
Accepted
time: 58ms
memory: 36076kb
Test #92:
score: 0
Accepted
time: 539ms
memory: 97744kb
Test #93:
score: 0
Accepted
time: 39ms
memory: 35620kb
Test #94:
score: 0
Accepted
time: 621ms
memory: 95260kb
Test #95:
score: 0
Accepted
time: 456ms
memory: 94944kb
Test #96:
score: 0
Accepted
time: 311ms
memory: 61324kb
Test #97:
score: 0
Accepted
time: 577ms
memory: 101384kb
Test #98:
score: 0
Accepted
time: 445ms
memory: 82128kb
Test #99:
score: 0
Accepted
time: 453ms
memory: 78836kb
Test #100:
score: 0
Accepted
time: 473ms
memory: 89888kb
Test #101:
score: 0
Accepted
time: 681ms
memory: 104672kb
Test #102:
score: 0
Accepted
time: 601ms
memory: 101268kb
Test #103:
score: 0
Accepted
time: 592ms
memory: 96012kb
Test #104:
score: 0
Accepted
time: 168ms
memory: 44112kb
Test #105:
score: 0
Accepted
time: 443ms
memory: 77504kb
Test #106:
score: 0
Accepted
time: 179ms
memory: 53580kb
Test #107:
score: 0
Accepted
time: 518ms
memory: 90708kb
Test #108:
score: 0
Accepted
time: 698ms
memory: 108660kb
Test #109:
score: 0
Accepted
time: 380ms
memory: 66628kb
Test #110:
score: 0
Accepted
time: 674ms
memory: 98276kb
Test #111:
score: 0
Accepted
time: 386ms
memory: 68108kb
Test #112:
score: 0
Accepted
time: 627ms
memory: 92488kb
Test #113:
score: 0
Accepted
time: 44ms
memory: 32256kb
Test #114:
score: 0
Accepted
time: 39ms
memory: 31428kb
Test #115:
score: 0
Accepted
time: 93ms
memory: 38048kb
Test #116:
score: 0
Accepted
time: 589ms
memory: 93416kb
Test #117:
score: 0
Accepted
time: 712ms
memory: 107968kb
Test #118:
score: 0
Accepted
time: 22ms
memory: 34208kb
Test #119:
score: 0
Accepted
time: 15ms
memory: 30904kb
Test #120:
score: 0
Accepted
time: 395ms
memory: 78192kb
Test #121:
score: 0
Accepted
time: 52ms
memory: 37960kb
Test #122:
score: 0
Accepted
time: 79ms
memory: 50580kb
Test #123:
score: 0
Accepted
time: 45ms
memory: 34096kb
Test #124:
score: 0
Accepted
time: 90ms
memory: 39688kb
Test #125:
score: 0
Accepted
time: 239ms
memory: 51852kb
Test #126:
score: 0
Accepted
time: 77ms
memory: 36444kb
Test #127:
score: 0
Accepted
time: 16ms
memory: 30112kb
Test #128:
score: 0
Accepted
time: 144ms
memory: 56652kb
Test #129:
score: 0
Accepted
time: 66ms
memory: 39668kb
Test #130:
score: 0
Accepted
time: 460ms
memory: 75684kb
Test #131:
score: 0
Accepted
time: 36ms
memory: 35920kb
Test #132:
score: 0
Accepted
time: 327ms
memory: 67800kb
Test #133:
score: 0
Accepted
time: 46ms
memory: 32920kb
Test #134:
score: 0
Accepted
time: 159ms
memory: 46508kb
Test #135:
score: 0
Accepted
time: 655ms
memory: 108920kb
Test #136:
score: 0
Accepted
time: 36ms
memory: 30884kb
Test #137:
score: 0
Accepted
time: 82ms
memory: 38204kb
Test #138:
score: 0
Accepted
time: 612ms
memory: 115176kb
Test #139:
score: 0
Accepted
time: 41ms
memory: 35016kb
Test #140:
score: 0
Accepted
time: 119ms
memory: 49092kb
Test #141:
score: 0
Accepted
time: 633ms
memory: 91388kb
Test #142:
score: 0
Accepted
time: 83ms
memory: 37824kb
Test #143:
score: 0
Accepted
time: 724ms
memory: 115148kb
Test #144:
score: 0
Accepted
time: 382ms
memory: 59688kb
Test #145:
score: 0
Accepted
time: 358ms
memory: 73996kb
Test #146:
score: 0
Accepted
time: 165ms
memory: 45152kb
Test #147:
score: 0
Accepted
time: 722ms
memory: 111052kb
Test #148:
score: 0
Accepted
time: 561ms
memory: 92572kb
Test #149:
score: 0
Accepted
time: 322ms
memory: 66620kb
Test #150:
score: 0
Accepted
time: 529ms
memory: 98040kb
Test #151:
score: 0
Accepted
time: 623ms
memory: 130788kb
Test #152:
score: 0
Accepted
time: 79ms
memory: 36468kb
Test #153:
score: 0
Accepted
time: 38ms
memory: 32872kb
Test #154:
score: 0
Accepted
time: 83ms
memory: 40104kb
Test #155:
score: 0
Accepted
time: 531ms
memory: 88664kb
Test #156:
score: 0
Accepted
time: 111ms
memory: 44680kb
Test #157:
score: 0
Accepted
time: 93ms
memory: 51324kb
Test #158:
score: 0
Accepted
time: 225ms
memory: 52824kb
Test #159:
score: 0
Accepted
time: 31ms
memory: 32076kb
Test #160:
score: 0
Accepted
time: 79ms
memory: 37044kb
Test #161:
score: 0
Accepted
time: 183ms
memory: 48560kb
Test #162:
score: 0
Accepted
time: 71ms
memory: 38816kb
Test #163:
score: 0
Accepted
time: 17ms
memory: 29480kb
Test #164:
score: 0
Accepted
time: 368ms
memory: 65064kb
Test #165:
score: 0
Accepted
time: 809ms
memory: 103664kb
Test #166:
score: 0
Accepted
time: 549ms
memory: 84912kb