QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235849 | #1811. How to Move the Beans | yx20220802 | WA | 2ms | 6044kb | C++14 | 3.5kb | 2023-11-03 11:07:43 | 2023-11-03 11:07:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace IO_ER{
#define LL long long
#define db double
#define U unsigned
#define ULL U LL
#define In inline
#define Re register
#define f(a,b,i) for(int i=a;i<=b;i++)
#define ff(a,b,i) for(int i=a;i<b;i++)
#define f_(a,b,i) for(int i=a;i>=b;i--)
#define ff_(a,b,i) for(int i=a;i>b;i--)
typedef pair<LL,int> Pi;
int inf=0x3f3f3f3f;
int INF=0x7fffffff;
LL infll=0x3f3f3f3f3f3f3f3fll;
LL INFll=0x7fffffffffffffffll;
template<typename T>void read(T &x){
x=0;
int fl=0;
char ch=getchar();
while(ch<'0'||'9'<ch){
if(ch=='-')fl=1;
ch=getchar();
}
while('0'<=ch&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
x=fl?-x:x;
}
template<typename T,typename ...Args>void read(T &x,Args &...args){
read(x);
read(args...);
}
}
using namespace IO_ER;
#define N 1050
int n,m;
char ch[N][N];
int L[N];
int R[N];
In int mex(int x,int y=3,int z=3){
if(x==-1||y==-1||z==-1)return -1;
int cnt[4]={0,0,0,0};
cnt[x]++;
cnt[y]++;
cnt[z]++;
if(!cnt[0])return 0;
if(!cnt[1])return 1;
if(!cnt[2])return 2;
return 3;
}
int sg[N][N];
int pre[N];
int nxt[N];
int pr1[N][3];
int pr2[N][3];
int sf1[N][3];
int sf2[N][3];
In void sol(){
read(n,m);
f(1,n,i)scanf("%s",ch[i]+1);
f(1,m,i)pre[i]=i-1,nxt[i]=i+1;
pre[1]=m;
nxt[m]=1;
f(1,m,j)sg[n+1][j]=3;
f(0,2,k)pr1[1][k]=pr2[1][k]=0;
f(0,2,k)sf1[m][k]=sf2[m][k]=0;
f_(n,1,i){
int fl=0;
f(1,m,j)fl|=(ch[i][j]=='#');
if(fl){
f(1,m,j)L[j]=R[j]=-1;
for(int j=1;L[j]==-1;j=nxt[j]){
if(ch[i][j]=='#')L[j]=3;
else if(L[pre[j]]!=-1)L[j]=mex(L[pre[j]],sg[i+1][j]);
}
for(int j=m;R[j]==-1;j=pre[j]){
if(ch[i][j]=='#')R[j]=3;
else if(R[nxt[j]]!=-1)R[j]=mex(R[nxt[j]],sg[i+1][j]);
}
f(1,m,j){
if(ch[i][j]=='#')sg[i][j]=3;
else sg[i][j]=mex(sg[i+1][j],L[pre[j]],R[nxt[j]]);
}
}
else{
if(m==1){
sg[i][1]=mex(sg[i+1][1]);
continue;
}
f(2,m,j){
f(0,2,k){
pr1[j][k]=mex(pr1[j-1][k],sg[i+1][j]);
pr2[j][k]=pr2[j-1][mex(k,sg[i+1][j-1])];
}
}
f_(m-1,1,j){
f(0,2,k){
sf1[j][k]=mex(sf1[j+1][k],sg[i+1][j]);
sf2[j][k]=sf2[j+1][mex(k,sg[i+1][j+1])];
}
}
sg[i][1]=mex(sg[i+1][1],sf1[2][mex(sg[i+1][m])],sf2[2][mex(sg[i+1][2])]);
sg[i][m]=mex(sg[i+1][m],pr1[m-1][mex(sg[i+1][1])],pr2[m-1][mex(sg[i+1][m-1])]);
f(2,m-1,j){
sg[i][j]=mex(sg[i+1][j],pr1[j-1][mex(sg[i+1][1],sf2[j+1][mex(sg[i+1][j+1])])],
sf1[j+1][mex(sg[i+1][m],pr2[j-1][mex(sg[i+1][j-1])])]);
}
}
}
int ans=0;
f(1,n,i){
f(1,m,j){
if(ch[i][j]=='B'){
ans^=sg[i][j];
}
}
}
puts(ans?"Alice":"Bob");
}
int main(){
int Ti;
Ti=1;
// read(Ti);
while(Ti--)sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5764kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 2ms
memory: 5308kb
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: 4132kb
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: 3892kb
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: 6044kb
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'