QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232313 | #1811. How to Move the Beans | c20230201 | WA | 3ms | 8128kb | C++14 | 2.8kb | 2023-10-30 09:58:54 | 2023-10-30 09:58:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char a[1005][1005];
int t[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) {
if(y<x) swap(x,y);
if(z<x) swap(x,z);
if(z<y) swap(y,z);
if(x) return 0;
if(y>1) return 1;
if(z>2) return 2;
return 3;
}
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];
if(a[i][j]=='#') sg[i][j]=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=1;i<=m;i++) sg[n+1][i]=3;
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++) 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;
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;
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--) {// sg[i][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++) {// sg[i][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 pl=(!sg[i+1][j-1]), pr=(!sg[i+1][j+1]);
sg[i][j]=mex2(sg[i+1][j],tl[rl[pr][j+1]][j-1],tr[rr[pl][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];
// cout<<sg[i][j]<<' ';
}
// cout<<'\n';
}
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: 3592kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5804kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 3ms
memory: 8128kb
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: 1ms
memory: 6136kb
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: 0ms
memory: 3800kb
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: -100
Wrong Answer
time: 1ms
memory: 5916kb
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:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'