QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232524 | #1811. How to Move the Beans | trsins | WA | 0ms | 3868kb | C++14 | 1.8kb | 2023-10-30 15:59:33 | 2023-10-30 15:59:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+4;
int n,m,f[N][N],L[N],R[N],Mex[5][5][5],Li[N][3],Ri[N][3],Lp[N][3],Rp[N][3],ans;
char s[N][N];
int mex(int x=-1,int y=-1,int z=-1){return Mex[x+1][y+1][z+1];}
int calcL(int x,int y){
if(~L[y]) return L[y];
int l=(y-1+m)%m;
return L[y]=mex(s[x][l]=='#'?calcL(x,l):-1,f[x+1][y]);
}
int calcR(int x,int y){
if(~R[y]) return R[y];
int r=(y+1)%m;
return R[y]=mex(s[x][r]=='#'?calcR(x,r):-1,f[x+1][y]);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
for(int i=-1;i<4;i++)for(int j=-1;j<4;j++)for(int k=-1;k<4;k++)
for(int l=0;l<4;l++)if((i^l)&&(j^l)&&(k^l)){Mex[i+1][j+1][k+1]=l;break;}
fill(f[n],f[n]+m,-1);
for(int i=n;i;i--){
bool fl=1;fill(f[i]+1,f[i]+m+1,-1);
for(int j=1;j<=m;j++)fl&=(s[i][j]=='#');
if(!fl){
fill(L+1,L+m+1,-1),fill(R+1,R+m+1,-1);
for(int j=1;j<=m;j++)if(s[i][j]=='#')calcL(i,j),calcR(i,j);
for(int j=1;j<=m;j++)if(s[i][j]=='#')f[i][j]=mex(L[(j-1+m)%m],R[(j+1)%m],f[i+1][j]);
}
else{
if(m==1){f[i][0]=mex(f[i+1][0]);continue;}
for(int j=2;j<=m;j++)for(int k=0;k<3;k++)Li[j][k]=mex(Li[j-1][k],f[i+1][j]);
for(int j=m-1;j;j--)for(int k=0;k<3;k++)Ri[j][k]=mex(Ri[j+1][k],f[i+1][j]);
for(int j=m-1;j;j--)for(int k=0;k<3;k++)Lp[j][k]=Lp[j+1][mex(f[i+1][j+1],k)];
for(int j=2;j<=m;j++)for(int k=0;k<3;k++)Rp[j][k]=Rp[j-1][mex(f[i+1][j-1],k)];
f[i][1]=mex(f[i+1][1],Lp[1][mex(f[i+1][2])],Rp[1][mex(f[i+1][m])]);
f[i][m]=mex(f[i+1][m],Li[m-1][mex(f[i+1][1])],Ri[m-1][mex(f[i+1][m-1])]);
for(int j=1;j<m;j++)f[i][j]=mex(
f[i+1][j],
Li[j-1][mex(f[i+1][1],Lp[j+1][mex(f[i+1][j+1])])],
Ri[j+1][mex(f[i+1][m],Rp[j-1][mex(f[i+1][j-1])])]
);
}
}
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(s[i][j]=='#')ans^=f[i][j];
puts(ans?"Alice":"Bob");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3740kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3868kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Alice
result:
wrong answer 1st words differ - expected: 'Bob', found: 'Alice'