QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#17924 | #2213. Knight | qingyu_orz | AC ✓ | 775ms | 130728kb | C++14 | 1.2kb | 2022-01-15 12:27:13 | 2022-05-04 16:23:12 |
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]){
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: 51ms
memory: 44668kb
Test #2:
score: 0
Accepted
time: 4ms
memory: 29300kb
Test #3:
score: 0
Accepted
time: 279ms
memory: 61140kb
Test #4:
score: 0
Accepted
time: 117ms
memory: 44504kb
Test #5:
score: 0
Accepted
time: 2ms
memory: 28344kb
Test #6:
score: 0
Accepted
time: 16ms
memory: 31668kb
Test #7:
score: 0
Accepted
time: 8ms
memory: 28936kb
Test #8:
score: 0
Accepted
time: 7ms
memory: 29124kb
Test #9:
score: 0
Accepted
time: 32ms
memory: 38788kb
Test #10:
score: 0
Accepted
time: 24ms
memory: 32788kb
Test #11:
score: 0
Accepted
time: 8ms
memory: 28736kb
Test #12:
score: 0
Accepted
time: 133ms
memory: 51088kb
Test #13:
score: 0
Accepted
time: 30ms
memory: 34644kb
Test #14:
score: 0
Accepted
time: 52ms
memory: 42768kb
Test #15:
score: 0
Accepted
time: 8ms
memory: 31584kb
Test #16:
score: 0
Accepted
time: 12ms
memory: 28776kb
Test #17:
score: 0
Accepted
time: 4ms
memory: 28500kb
Test #18:
score: 0
Accepted
time: 24ms
memory: 31964kb
Test #19:
score: 0
Accepted
time: 11ms
memory: 30000kb
Test #20:
score: 0
Accepted
time: 27ms
memory: 38320kb
Test #21:
score: 0
Accepted
time: 8ms
memory: 28216kb
Test #22:
score: 0
Accepted
time: 4ms
memory: 28596kb
Test #23:
score: 0
Accepted
time: 2ms
memory: 28212kb
Test #24:
score: 0
Accepted
time: 8ms
memory: 30072kb
Test #25:
score: 0
Accepted
time: 6ms
memory: 30172kb
Test #26:
score: 0
Accepted
time: 4ms
memory: 28372kb
Test #27:
score: 0
Accepted
time: 4ms
memory: 28340kb
Test #28:
score: 0
Accepted
time: 160ms
memory: 63900kb
Test #29:
score: 0
Accepted
time: 11ms
memory: 29132kb
Test #30:
score: 0
Accepted
time: 20ms
memory: 33372kb
Test #31:
score: 0
Accepted
time: 19ms
memory: 31828kb
Test #32:
score: 0
Accepted
time: 6ms
memory: 28484kb
Test #33:
score: 0
Accepted
time: 221ms
memory: 55372kb
Test #34:
score: 0
Accepted
time: 11ms
memory: 30704kb
Test #35:
score: 0
Accepted
time: 165ms
memory: 54156kb
Test #36:
score: 0
Accepted
time: 254ms
memory: 54924kb
Test #37:
score: 0
Accepted
time: 20ms
memory: 29372kb
Test #38:
score: 0
Accepted
time: 50ms
memory: 33424kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 29344kb
Test #40:
score: 0
Accepted
time: 1ms
memory: 28932kb
Test #41:
score: 0
Accepted
time: 19ms
memory: 33136kb
Test #42:
score: 0
Accepted
time: 23ms
memory: 32924kb
Test #43:
score: 0
Accepted
time: 27ms
memory: 35824kb
Test #44:
score: 0
Accepted
time: 8ms
memory: 28420kb
Test #45:
score: 0
Accepted
time: 10ms
memory: 30312kb
Test #46:
score: 0
Accepted
time: 2ms
memory: 28408kb
Test #47:
score: 0
Accepted
time: 6ms
memory: 29808kb
Test #48:
score: 0
Accepted
time: 207ms
memory: 49576kb
Test #49:
score: 0
Accepted
time: 41ms
memory: 40480kb
Test #50:
score: 0
Accepted
time: 20ms
memory: 34848kb
Test #51:
score: 0
Accepted
time: 437ms
memory: 76820kb
Test #52:
score: 0
Accepted
time: 418ms
memory: 80512kb
Test #53:
score: 0
Accepted
time: 80ms
memory: 37512kb
Test #54:
score: 0
Accepted
time: 604ms
memory: 112004kb
Test #55:
score: 0
Accepted
time: 307ms
memory: 54296kb
Test #56:
score: 0
Accepted
time: 637ms
memory: 104616kb
Test #57:
score: 0
Accepted
time: 252ms
memory: 53276kb
Test #58:
score: 0
Accepted
time: 35ms
memory: 31844kb
Test #59:
score: 0
Accepted
time: 82ms
memory: 37404kb
Test #60:
score: 0
Accepted
time: 707ms
memory: 108856kb
Test #61:
score: 0
Accepted
time: 230ms
memory: 50760kb
Test #62:
score: 0
Accepted
time: 173ms
memory: 43612kb
Test #63:
score: 0
Accepted
time: 488ms
memory: 80976kb
Test #64:
score: 0
Accepted
time: 82ms
memory: 37464kb
Test #65:
score: 0
Accepted
time: 600ms
memory: 106012kb
Test #66:
score: 0
Accepted
time: 76ms
memory: 37264kb
Test #67:
score: 0
Accepted
time: 314ms
memory: 61632kb
Test #68:
score: 0
Accepted
time: 46ms
memory: 37264kb
Test #69:
score: 0
Accepted
time: 727ms
memory: 114012kb
Test #70:
score: 0
Accepted
time: 179ms
memory: 46128kb
Test #71:
score: 0
Accepted
time: 150ms
memory: 46504kb
Test #72:
score: 0
Accepted
time: 53ms
memory: 35928kb
Test #73:
score: 0
Accepted
time: 77ms
memory: 47032kb
Test #74:
score: 0
Accepted
time: 621ms
memory: 106652kb
Test #75:
score: 0
Accepted
time: 302ms
memory: 58716kb
Test #76:
score: 0
Accepted
time: 396ms
memory: 63320kb
Test #77:
score: 0
Accepted
time: 587ms
memory: 92108kb
Test #78:
score: 0
Accepted
time: 51ms
memory: 35728kb
Test #79:
score: 0
Accepted
time: 107ms
memory: 39584kb
Test #80:
score: 0
Accepted
time: 312ms
memory: 60012kb
Test #81:
score: 0
Accepted
time: 260ms
memory: 57412kb
Test #82:
score: 0
Accepted
time: 285ms
memory: 55252kb
Test #83:
score: 0
Accepted
time: 120ms
memory: 49472kb
Test #84:
score: 0
Accepted
time: 133ms
memory: 42228kb
Test #85:
score: 0
Accepted
time: 70ms
memory: 36712kb
Test #86:
score: 0
Accepted
time: 61ms
memory: 36656kb
Test #87:
score: 0
Accepted
time: 71ms
memory: 40680kb
Test #88:
score: 0
Accepted
time: 65ms
memory: 36760kb
Test #89:
score: 0
Accepted
time: 633ms
memory: 106668kb
Test #90:
score: 0
Accepted
time: 308ms
memory: 55976kb
Test #91:
score: 0
Accepted
time: 64ms
memory: 36032kb
Test #92:
score: 0
Accepted
time: 639ms
memory: 97704kb
Test #93:
score: 0
Accepted
time: 47ms
memory: 35272kb
Test #94:
score: 0
Accepted
time: 586ms
memory: 95196kb
Test #95:
score: 0
Accepted
time: 472ms
memory: 94952kb
Test #96:
score: 0
Accepted
time: 302ms
memory: 61116kb
Test #97:
score: 0
Accepted
time: 583ms
memory: 101312kb
Test #98:
score: 0
Accepted
time: 455ms
memory: 82124kb
Test #99:
score: 0
Accepted
time: 490ms
memory: 78816kb
Test #100:
score: 0
Accepted
time: 615ms
memory: 90036kb
Test #101:
score: 0
Accepted
time: 712ms
memory: 104716kb
Test #102:
score: 0
Accepted
time: 565ms
memory: 101248kb
Test #103:
score: 0
Accepted
time: 580ms
memory: 96076kb
Test #104:
score: 0
Accepted
time: 187ms
memory: 44108kb
Test #105:
score: 0
Accepted
time: 409ms
memory: 77592kb
Test #106:
score: 0
Accepted
time: 189ms
memory: 53660kb
Test #107:
score: 0
Accepted
time: 482ms
memory: 90752kb
Test #108:
score: 0
Accepted
time: 641ms
memory: 108764kb
Test #109:
score: 0
Accepted
time: 379ms
memory: 66416kb
Test #110:
score: 0
Accepted
time: 640ms
memory: 98296kb
Test #111:
score: 0
Accepted
time: 395ms
memory: 68168kb
Test #112:
score: 0
Accepted
time: 592ms
memory: 92400kb
Test #113:
score: 0
Accepted
time: 29ms
memory: 34240kb
Test #114:
score: 0
Accepted
time: 28ms
memory: 31500kb
Test #115:
score: 0
Accepted
time: 71ms
memory: 37848kb
Test #116:
score: 0
Accepted
time: 511ms
memory: 93384kb
Test #117:
score: 0
Accepted
time: 706ms
memory: 107764kb
Test #118:
score: 0
Accepted
time: 27ms
memory: 34264kb
Test #119:
score: 0
Accepted
time: 16ms
memory: 30832kb
Test #120:
score: 0
Accepted
time: 371ms
memory: 78200kb
Test #121:
score: 0
Accepted
time: 51ms
memory: 37992kb
Test #122:
score: 0
Accepted
time: 100ms
memory: 51052kb
Test #123:
score: 0
Accepted
time: 49ms
memory: 34620kb
Test #124:
score: 0
Accepted
time: 80ms
memory: 39740kb
Test #125:
score: 0
Accepted
time: 230ms
memory: 51932kb
Test #126:
score: 0
Accepted
time: 52ms
memory: 36360kb
Test #127:
score: 0
Accepted
time: 26ms
memory: 31540kb
Test #128:
score: 0
Accepted
time: 132ms
memory: 56664kb
Test #129:
score: 0
Accepted
time: 60ms
memory: 39444kb
Test #130:
score: 0
Accepted
time: 476ms
memory: 75684kb
Test #131:
score: 0
Accepted
time: 56ms
memory: 36048kb
Test #132:
score: 0
Accepted
time: 321ms
memory: 67676kb
Test #133:
score: 0
Accepted
time: 51ms
memory: 32956kb
Test #134:
score: 0
Accepted
time: 147ms
memory: 46424kb
Test #135:
score: 0
Accepted
time: 633ms
memory: 108712kb
Test #136:
score: 0
Accepted
time: 34ms
memory: 31768kb
Test #137:
score: 0
Accepted
time: 66ms
memory: 38328kb
Test #138:
score: 0
Accepted
time: 608ms
memory: 115032kb
Test #139:
score: 0
Accepted
time: 41ms
memory: 35244kb
Test #140:
score: 0
Accepted
time: 124ms
memory: 48896kb
Test #141:
score: 0
Accepted
time: 628ms
memory: 91432kb
Test #142:
score: 0
Accepted
time: 90ms
memory: 39332kb
Test #143:
score: 0
Accepted
time: 775ms
memory: 115244kb
Test #144:
score: 0
Accepted
time: 354ms
memory: 59660kb
Test #145:
score: 0
Accepted
time: 366ms
memory: 74060kb
Test #146:
score: 0
Accepted
time: 185ms
memory: 45344kb
Test #147:
score: 0
Accepted
time: 691ms
memory: 111180kb
Test #148:
score: 0
Accepted
time: 587ms
memory: 92416kb
Test #149:
score: 0
Accepted
time: 351ms
memory: 66656kb
Test #150:
score: 0
Accepted
time: 539ms
memory: 97892kb
Test #151:
score: 0
Accepted
time: 626ms
memory: 130728kb
Test #152:
score: 0
Accepted
time: 54ms
memory: 36392kb
Test #153:
score: 0
Accepted
time: 35ms
memory: 33948kb
Test #154:
score: 0
Accepted
time: 74ms
memory: 39072kb
Test #155:
score: 0
Accepted
time: 548ms
memory: 88772kb
Test #156:
score: 0
Accepted
time: 115ms
memory: 44760kb
Test #157:
score: 0
Accepted
time: 84ms
memory: 51268kb
Test #158:
score: 0
Accepted
time: 216ms
memory: 52876kb
Test #159:
score: 0
Accepted
time: 41ms
memory: 32336kb
Test #160:
score: 0
Accepted
time: 73ms
memory: 37044kb
Test #161:
score: 0
Accepted
time: 196ms
memory: 48596kb
Test #162:
score: 0
Accepted
time: 78ms
memory: 38832kb
Test #163:
score: 0
Accepted
time: 18ms
memory: 30276kb
Test #164:
score: 0
Accepted
time: 376ms
memory: 65024kb
Test #165:
score: 0
Accepted
time: 706ms
memory: 103720kb
Test #166:
score: 0
Accepted
time: 469ms
memory: 84756kb