QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232339 | #1811. How to Move the Beans | c20230201 | WA | 20ms | 7800kb | C++14 | 2.7kb | 2023-10-30 11:08:21 | 2023-10-30 11:08:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char a[1005][1005];
int sg[1005][1005];
int L[1005], R[1005];
int nl[1005], nr[1005];
int tl[4][1005], tr[4][1005], rl[4][1005], rr[4][1005];
int mex(int x,int y) {
if(x>y) swap(x,y);
if(x) return 0;
if(y>1) return 1;
return 2;
}
int mex2(int x,int y,int z) {
int vis[4]={};
vis[x]=vis[y]=vis[z]=1;
int res=0;
while(vis[res]) ++res;
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n,m; cin>>n>>m;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
cin>>a[i][j];
}
}
for(int i=1;i<=m;i++) sg[n+1][i]=3;
for(int i=1;i<m;i++) nr[i]=i+1;
for(int i=2;i<=m;i++) nl[i]=i-1;
nr[m]=1, nl[1]=m;
for(int i=n;i>=1;i--) {
int flag=0;
for(int j=1;j<=m;j++) if(a[i][j]=='#') flag=1;
if(flag) {
for(int j=1;j<=m;j++) {
if(a[i][j]=='#') {
L[j]=R[j]=3;
for(int k=nl[j];a[i][k]!='#';k=nl[k]) R[k]=mex(R[nr[k]],sg[i+1][k]);
for(int k=nr[j];a[i][k]!='#';k=nr[k]) L[k]=mex(L[nl[k]],sg[i+1][k]);
}
}
for(int j=1;j<=m;j++) {
if(a[i][j]=='#') sg[i][j]=3;
else sg[i][j]=mex2(L[nl[j]],R[nr[j]],sg[i+1][j]);
}
}else {
if(m==1) {
sg[i][1]=(!sg[i+1][1]);
continue;
}
for(int t=0;t<=3;t++) {// L[m]=t, L[j]=?
int lst=t; tl[t][m]=t;
for(int j=1;j<m;j++) tl[t][j]=mex(lst,sg[i+1][j]), lst=tl[t][j];
}
for(int t=0;t<=3;t++) {// R[1]=t, R[j]=?
int lst=t; tr[t][1]=t;
for(int j=m;j>1;j--) tr[t][j]=mex(lst,sg[i+1][j]), lst=tr[t][j];
}
for(int t=0;t<=3;t++) rl[t][m]=t;
for(int j=m-1;j>=1;j--) {// L[j]=t, L[m]=?
for(int t=0;t<=3;t++) {
int pl=mex(t,sg[i+1][j+1]);
rl[t][j]=rl[pl][j+1];
}
}
for(int t=0;t<=3;t++) rr[t][1]=t;
for(int j=2;j<=m;j++) {// R[j]=t, R[1]=?
for(int t=0;t<=3;t++) {
int pr=mex(t,sg[i+1][j-1]);
rr[t][j]=rr[pr][j-1];
}
}
for(int j=1;j<=m;j++) {
if(j==1) {
L[2]=(!sg[i+1][2]), R[m]=(!sg[i+1][m]);
for(int k=3;k<=m;k++) L[k]=mex(L[nl[k]],sg[i+1][k]);
for(int k=m-1;k>=2;k--) R[k]=mex(R[nr[k]],sg[i+1][k]);
sg[i][j]=mex2(L[m],R[2],sg[i+1][j]);
}else if(j==m) {
L[1]=(!sg[i+1][1]), R[m-1]=(!sg[i+1][m-1]);
for(int k=2;k<m;k++) L[k]=mex(L[nl[k]],sg[i+1][k]);
for(int k=m-2;k>=1;k--) R[k]=mex(R[nr[k]],sg[i+1][k]);
sg[i][j]=mex2(L[m-1],R[1],sg[i+1][j]);
}else {
int pr=(!sg[i+1][j-1]), pl=(!sg[i+1][j+1]);
sg[i][j]=mex2(sg[i+1][j],tl[rl[pl][j+1]][j-1],tr[rr[pr][j-1]][j+1]);
}
}
}
}
int ans=0;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(a[i][j]=='B') ans^=sg[i][j];
}
}
if(ans) cout<<"Alice\n";
else cout<<"Bob\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5096kb
input:
293 249 #B..B..BBB..B.B.B...#BBB..B#B.BBB.#B##B.BB.B.##B#B.BB..B.#B#BB.BB##B#BB#...B..BB..B.B##B.B#B.#.##..B.#..BBBB#.BB..#.BBB#B##BB....B.##B..#...B#..B.BB#B.#...B#.BB.#B#.B...BBB.B.B..B....##.B..B##.BB#B.B.BBB.B#B..#.B.B#.B##..B#.##BB.#BB#.BB.#.B..BB.BB.B BB.B.#.B#BB.B.B..B.###.B...BB.##.B...B#BB....
output:
Alice
result:
ok "Alice"
Test #6:
score: 0
Accepted
time: 0ms
memory: 4104kb
input:
75 13 BBB.B.BB.B.#B BB.##...B##BB ..#.B....#.B. BBB..#...B#BB #B#.##B..BB.. #B..BBBB.B..# #B##.BBBBB.B# BBB.B..#B#B.. .BBB####.##BB .B##...#.#.#. #.BB#..B.B.B. BB#BB.BBB..BB B.#...#.BBBBB ..#B.BBBB..B# BB..B..#..... ..B..BBBB.B#. .B.B##B.#B.## BBBB#...#..B# B.BB..BBB#B.B .#B#B...BB.BB #.B...BB...B. ...
output:
Alice
result:
ok "Alice"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5920kb
input:
35 38 #.#..B.B.#.BB#.B.B.B..##..B#B###BBB##. .#.#.B#.#BBB..B..BB.#..BB..##B......#B B.B#..B..B...##B#B..#.##.#..B.#..B##BB #.B.B..#..B#.#.B#B##B.BBB..#.B...B..#. B#.#.BBB..B.BB.B..BBBBB##B..BB#.B#.BB. B##.B#...B.B.BB.BBB..#BBB.#..#B#.B..#B B....B#B.#.BBB.B#BB...##B#...B..BB.BB. ..###.#.B#....#.....#...
output:
Alice
result:
ok "Alice"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5896kb
input:
36 106 BB.B..B.BBBB.BB..BB..BB..BB...BB.B..B.B..BBBB.B.BB..B.B..BB..BBBB.B.B.BBBB..B.BBBBBBBBBBBBBBB.BB.B.BBB..BB #BBB.BBB#..#.BB...###B.B#.B...B.#.BBBB.B..B..#B.#B#BB##.BB.#B..B#B...B....B#B#.#B.B.B.BB#..B#B#.#.#B###.B. B.BBB.BBBBB.BBB....BB..B.BBBB.BBB.BBB.BBB.B.B.BBB.B...B.B.BBBBB.BBB....BB.BBB.B...
output:
Alice
result:
ok "Alice"
Test #9:
score: 0
Accepted
time: 0ms
memory: 4872kb
input:
245 239 .BBB.BB.B.BBB..B.BB.BBBBBB..B.BBB.B.BBBBBBBBB..B..BB.B.B.BB..B.BB...B.BB.B.BB..BBB..BB..BB.BBB.BBB.BBBBB.BBBB.BB.BBBB...BBB.B..BBBBBBB..BB..B.B.B..BBBBB...BB..BBB...BBB.B..BB.BB.B.BB.BBB..B.B.BBBB.BBBBB.BBB.BBBB.BB...B.B.B...BBB.BBB.BBB..B B#.#BB..#BB.BBB#..BB..#.B#.##B.BBB###..B#B...BB..#.#...
output:
Bob
result:
ok "Bob"
Test #10:
score: 0
Accepted
time: 2ms
memory: 6940kb
input:
288 94 B....BB....BB.BBB.BBBB..B.B.B.....BBBB.B..BBBBBB.B..BBBBBBB....BBB.BBBBB.B.BBBB..B..B.B.BBB..B BB#.#B#BBB.B#BB..BBB.B#BB#B#BB#BBBBBB####.B.B...BBB.BB.B.#.B.B.B.#.B.B.#.#..B..BB..B#..B.#.... BBBBBBB...B.BB.B..BB..BBBB.BBBBB.BBBB..BBBBBB.BB....B.BBBB.BB.BBB..B.BBBB.B.BBBBBB..BBB.BBB.B. .B....B....
output:
Alice
result:
ok "Alice"
Test #11:
score: 0
Accepted
time: 0ms
memory: 7800kb
input:
119 1 B . # . B . # # # . B B # B # # # B # B . . B B B B . B B B B # # . B B B . B . # B B . # B . # . B B B B B B # # B B B # . . # . B B B B . B B . B B B # # B B . # # B B . B . # . B B B B # B . B B . B B . # # B . . . # . . B . . B . . #
output:
Alice
result:
ok "Alice"
Test #12:
score: 0
Accepted
time: 0ms
memory: 7784kb
input:
196 1 . B # . . # B . . . . B B B # . . B # B . B B # . B B . B B B . B . . . B # . . . . . B . B . . . B # B B . . B B # . . # . # B . # . B B . B B B . B B B # . . B . # . . . B . . B B . B . B . . # . . # B B # # . . . B B # . B # B . . # . . . B . . B B # # B . # B # . B . B B . # . . . . # B B ...
output:
Bob
result:
ok "Bob"
Test #13:
score: 0
Accepted
time: 1ms
memory: 4436kb
input:
148 1 . B B . . # B . # . B . . . . B . . . B . B # . # B B . . . B B B # . # . # # . # B . B B B B B . B . . # B B . . . . # . . # B . B . . . B . . . B B . . B . B . . . B B # . . . . B . B . B . . . . # # B . . B . # . # . B # B . . . # . B . B # B B # . B B B . . . . B # B # B B # B # B B B B . B
output:
Alice
result:
ok "Alice"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
2 5 ...#. .#B..
output:
Alice
result:
ok "Alice"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
2 4 B..B ....
output:
Bob
result:
ok "Bob"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
8 1 . B . . . B . .
output:
Bob
result:
ok "Bob"
Test #17:
score: 0
Accepted
time: 4ms
memory: 7764kb
input:
803 520 BBB#...B.BBB.BBBB#.#BBB.#BBB.BBB.BB.BB..B#BBB##.#BB.#BBBB.BB#BB.###BBBBB.BBBBB.#.BBBBBB#BBB#.B.BB.####BBBB...#.BBBBBBBB#BBB#BBB##B#B..#BBB.BB#.BBBBB#.BB#B..BBBB.BBBB.BB.BBBBB##B#BB.BB#B##B#BBBBB.BBBBBB#BBB##BBBBB##B.B.BBB.B.BBBBB#B#BB.BBBBBB..#B.##BB...B.B.BBBBB..BB.B.##BBBB#B#..#BBBBBBBBBB#...
output:
Alice
result:
ok "Alice"
Test #18:
score: -100
Wrong Answer
time: 20ms
memory: 7400kb
input:
713 987 B.BB#.BBB#B#BB#BBBBBBB##.BBB..B#..B..BBBBBBBB#BB#BB..BB..##BBBBBBB#BBBBB.#BBBBB#B..BBBBBB.BB#B#BBBBBB#BB.B#BB#B..B#B.B#.B#BB.BB.BBBBB.BB#B#B#B.B##BB##B#BB##..#BB#.B.B.#.B#BB.BBBBBBB#BBBB.#.B.#BBB#BB.BBBB.B...B##B..#BB.BBBB.##..#B.B##BBBB.B#BBB##.B#BB.BB..BB#B.BB.#..#.#BB#B#..BBBBBBB.BBBB.B#B...
output:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'