QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235233 | #1811. How to Move the Beans | c20230507 | WA | 3ms | 15912kb | C++14 | 2.9kb | 2023-11-02 16:17:49 | 2023-11-02 16:17:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int INF=0x3f3f3f3f;
int t,n,m;
char a[1005][1005];
int dp[1005][1005],lf[1005][1005],lt[1005][1005],rt[1005][1005],rf[1005][1005];
int L[maxn],R[maxn];
int mex(int x){
if(x!=0)return 0;
return 1;
}
int mex2(int x,int y){
int vis[4]={0,0,0,0};
vis[x]=vis[y]=1;
for(int i=0;i<4;i++)if(!vis[i])return i;
return 114514;
}
int mex3(int x,int y,int z){
int vis[4]={0,0,0,0};
vis[x]=vis[y]=vis[z]=1;
for(int i=0;i<4;i++)if(!vis[i])return i;
return 114514;
}
int main(){
// freopen("chequer.in","r",stdin);
// freopen("chequer.out","w",stdout);
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
while(t--){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)cin>>a[i][j];
}
for(int j=0;j<=m+1;j++)dp[n+1][j]=3;
for(int i=n;i>=1;i--){
for(int j=0;j<=m+1;j++)L[j]=R[j]=0;
int flag=0;
for(int j=1;j<=m;j++)if(a[i][j]=='#')flag++;
if(m==1){
if(!flag)dp[i][1]=mex(dp[i+1][1]);
else dp[i][1]=3;
continue;
}
if(!flag){
for(int k=0;k<=3;k++)lf[m][k]=rf[1][k]=lt[1][k]=rt[m][k]=k;
for(int j=m-1;j>=1;j--){
for(int k=0;k<=3;k++){
lf[j][k]=lf[j+1][mex2(k,dp[i+1][j+1])];
}
}
for(int j=2;j<=m;j++){
for(int k=0;k<=3;k++){
lt[j][k]=mex2(dp[i+1][j],lt[j-1][k]);
}
}
for(int j=2;j<=m;j++){
for(int k=0;k<=3;k++){
rf[j][k]=rf[j-1][mex2(k,dp[i+1][j-1])];
}
}
for(int j=m-1;j>=1;j--){
for(int k=0;k<=3;k++){
rt[j][k]=mex2(dp[i+1][j],rt[j+1][k]);
}
}
dp[i][1]=mex3(dp[i+1][1],lf[2][mex(dp[i+1][2])],rt[2][mex(dp[i+1][m])]);
dp[i][m]=mex3(dp[i+1][m],lt[m-1][mex(dp[i+1][1])],rf[m-1][mex(dp[i+1][m-1])]);
for(int j=2;j<m;j++){
int v1=mex2(dp[i+1][j-1],lt[j-1][mex2(dp[i+1][1],lf[j+1][mex(dp[i+1][j+1])])]);
int v2=mex2(dp[i+1][j+1],rt[j+1][mex2(dp[i+1][m],rf[j-1][mex(dp[i+1][j-1])])]);
dp[i][j]=mex3(dp[i+1][j],v1,v2);
}
}
else{
for(int j=1;j<=m;j++){
if(a[i][j]=='#'){
L[j]=R[j]=3;
for(int k=(j==m?1:j+1);a[i][k]!='#';k=(k==m?1:k+1))L[k]=mex2(L[(k==1?m:k-1)],dp[i+1][k]);
for(int k=(j==1?m:j-1);a[i][k]!='#';k=(k==1?m:k-1))R[k]=mex2(R[(k==m?1:k+1)],dp[i+1][k]);
}
}
for(int j=1;j<=m;j++){
if(a[i][j]=='#')dp[i][j]=3;
else dp[i][j]=mex3(L[j==1?m:j-1],R[j==m?1:j+1],dp[i+1][j]);
}
// dp[i][1]=mex3(dp[i+1][1],L[m],R[2]);dp[i][m]=mex3(dp[i+1][m],L[m-1],R[1]);
// for(int j=2;j<m;j++){
// dp[i][j]=mex3(dp[i+1][j],L[j-1],R[j+1]);
// }
}
// cout<<R[3]<<endl;
}
// cout<<"\n";
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='B')ans=(ans^dp[i][j]);
}
}
// cout<<dp[1][1]<<endl;
if(ans)cout<<"Alice\n";
else cout<<"Bob\n";
}
return 0;
}
//3
//2 3
//B.#
//#..
//1 1
//b
//1 3
//B#.
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7780kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7796kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7784kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 3ms
memory: 7988kb
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: -100
Wrong Answer
time: 0ms
memory: 15912kb
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:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'