QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232655 | #1811. How to Move the Beans | Edwin_VanCleef | WA | 8ms | 15076kb | C++14 | 3.3kb | 2023-10-30 18:50:10 | 2023-10-30 18:50:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_IO{
#define ll long long
#define ull unsigned long long
#define ld long double
#define spc putchar(' ')
#define et putchar('\n')
template<class T>
void read(T &num){
T x=0,f=1;
char c=getchar();
while(!isdigit(c)){
if(c=='-') f=-1;
c=getchar();
}
while(isdigit(c)){
x=(x<<3)+(x<<1)+c-48;
c=getchar();
}
num=f*x;
}
template<class T>
void write(T x){
static char buf[40];
static int len=-1;
if(x<0) putchar('-'),x=-x;
do{
buf[++len]=x%10+48;
x/=10;
}while(x);
while(len>=0) putchar(buf[len--]);
}
}
using namespace my_IO;
const ll maxn=1010;
ll n,m,a[maxn][maxn],f[maxn][maxn],L[maxn],R[maxn],lf[maxn][4],rf[maxn][4],lt[maxn][4],rt[maxn][4];
ll mex(ll a){
if(a!=0) return 0;
return 1;
}
ll mex(ll a,ll b){
if(a!=0&&b!=0) return 0;
if(a==1||b==1) return 2;
return 1;
}
ll mex(ll a,ll b,ll c){
if(a!=0&&b!=0&&c!=0) return 0;
if(a!=1&&b!=1&&c!=1) return 1;
if(a!=2&&b!=2&&c!=2) return 2;
return 3;
}
void solve(){
read(n),read(m);
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
char c;
cin>>c;
if(c=='#') a[i][j]=1;
if(c=='B') a[i][j]=2;
}
}
memset(f,-1,sizeof(f));
for(ll i=n;i>=1;i--){
memset(L,-1,sizeof(L));
memset(R,-1,sizeof(R));
memset(lf,-1,sizeof(lf));
memset(rf,-1,sizeof(rf));
memset(lt,-1,sizeof(lt));
memset(rt,-1,sizeof(rt));
ll flag=0;
for(ll j=1;j<=m;j++) if(a[i][j]==1) flag=1;
if(flag){
ll pos=0;
for(ll j=1;j<=m;j++) if(a[i][j]==1) pos=j;
for(ll j=pos%m+1;j!=pos;j=j%m+1){
if(a[i][j]==1) continue;
L[j]=mex(L[(j-2+m)%m+1],f[i+1][j]);
}
for(ll j=(pos-2+m)%m+1;j!=pos;j=(j-2+m)%m+1){
if(a[i][j]==1) continue;
R[j]=mex(R[j+1],f[i+1][j]);
}
for(ll j=1;j<=m;j++) f[i][j]=mex(f[i+1][j],L[(j-2+m)%m+1],R[j%m+1]);
continue;
}
for(ll j=0;j<=3;j++) lt[1][j]=rt[m][j]=lf[m][j]=rf[1][j]=j;
for(ll j=2;j<=m;j++) for(ll k=0;k<=3;k++) lt[j][k]=mex(lt[j-1][k],f[i+1][j]);
for(ll j=m-1;j;j--) for(ll k=0;k<=3;k++) rt[j][k]=mex(rt[j+1][k],f[i+1][j]);
for(ll j=m-1;j;j--) for(ll k=0;k<=3;k++) lf[j][k]=lf[j+1][mex(f[i+1][j+1],k)];
for(ll j=2;j<=m;j++) for(ll k=0;k<=3;k++) rf[j][k]=rf[j-1][mex(f[i+1][j-1],k)];
f[i][1]=mex(lf[2][mex(f[i+1][2])],rt[2][mex(f[i+1][m])],f[i+1][1]);
f[i][m]=mex(lt[m-1][mex(f[i+1][1])],rf[m-1][mex(f[i+1][m-1])],f[i+1][m]);
for(ll j=2;j<m;j++){
L[j-1]=lt[j-1][mex(lf[j+1][mex(f[i+1][j+1])],f[i+1][1])];
R[j+1]=rt[j+1][mex(rf[j-1][mex(f[i+1][j-1])],f[i+1][m])];
f[i][j]=mex(L[j-1],R[j+1],f[i+1][j]);
}
}
ll res=0;
for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) if(a[i][j]==2) res^=f[i][j];
if(res) puts("Alice");
else puts("Bob");
}
int main(){
int t=1;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12596kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11864kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 12120kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 2ms
memory: 12256kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 8ms
memory: 15076kb
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: 13568kb
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: 3ms
memory: 13464kb
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: 13728kb
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: 7ms
memory: 14160kb
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: 0ms
memory: 14420kb
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: -100
Wrong Answer
time: 0ms
memory: 12580kb
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:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'