QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232537 | #1811. How to Move the Beans | trsins | WA | 2ms | 6516kb | C++14 | 1.9kb | 2023-10-30 16:14:37 | 2023-10-30 16:14:38 |
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?y-1: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%m+1;
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+1]+1,f[n+1]+m+1,-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?j-1:m],R[j%m+1],f[i+1][j]);
}
else{
if(m==1){f[i][1]=mex(f[i+1][1]);continue;}
for(int k=0;k<3;k++)Li[1][k]=Lp[m][k]=Ri[m][k]=Rp[1][k]=k;
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[2][mex(f[i+1][2])],Rp[2][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=2;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]=='B')ans^=f[i][j];
puts(ans?"Alice":"Bob");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 2ms
memory: 6072kb
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: 5792kb
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: 5908kb
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: 0ms
memory: 3824kb
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: 2ms
memory: 6516kb
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: 1ms
memory: 6320kb
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: 4428kb
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: 1ms
memory: 6040kb
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: 4560kb
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: 5856kb
input:
2 5 ...#. .#B..
output:
Alice
result:
ok "Alice"
Test #15:
score: -100
Wrong Answer
time: 1ms
memory: 5788kb
input:
2 4 B..B ....
output:
Alice
result:
wrong answer 1st words differ - expected: 'Bob', found: 'Alice'