QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232587#1811. How to Move the Beansc20230507WA 4ms16088kbC++142.4kb2023-10-30 17:04:582023-10-30 17:04:58

Judging History

你现在查看的是最新测评结果

  • [2023-10-30 17:04:58]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:16088kb
  • [2023-10-30 17:04:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int INF=0x3f3f3f3f;
int n,m,lt[maxn][4],rt[maxn][4],lf[maxn][4],rf[maxn][4],L[maxn],R[maxn];
int dp[1005][1005];
char a[1005][1005];
int mex1(int x){
	if(x!=0)return 0;
	return 1;
}
int mex(int x,int y){
	int vis[4]={0,0,0,0};
	vis[x]=vis[y]=1;
	for(int i=0;i<=3;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<=3;i++)if(!vis[i])return i;
	return 114514;
}
void init(int i){
	for(int k=0;k<=3;k++)lt[1][k]=lf[m][k]=rt[m][k]=rf[1][k]=k;
	for(int j=2;j<=m;j++){
		for(int k=0;k<=3;k++)lt[j][k]=mex(lt[j-1][k],dp[i+1][j]);
	}
	for(int j=m-1;j>=1;j--){
		for(int k=0;k<=3;k++)rt[j][k]=mex(rt[j+1][k],dp[i+1][j]);
	}
	for(int j=m-1;j>=1;j--){
		for(int k=0;k<=3;k++)lf[j][k]=lf[j+1][mex(k,dp[i+1][j+1])];
	}
	for(int j=2;j<=m;j++){
		for(int k=0;k<=3;k++)rf[j][k]=rf[j-1][mex(k,dp[i+1][j-1])];
	}
}
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	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--){
		int siz=0;
		for(int j=1;j<=m;j++)siz=siz+(a[i][j]=='#');
		if(m==1){
			if(siz==1)dp[i][1]=3;
			else dp[i][1]=mex1(dp[i+1][1]);
			continue;
		}
		if(siz==0){
			init(i);
			dp[i][1]=mex3(lf[2][mex1(dp[i+1][2])],rt[2][mex1(dp[i+1][m])],dp[i+1][1]);
			dp[i][m]=mex3(rf[m-1][mex1(dp[i+1][m-1])],lt[m-1][mex1(dp[i+1][1])],dp[i+1][m]);
			for(int j=2;j<m;j++){
				L[j-1]=lt[j-1][mex(lf[j+1][mex1(dp[i-1][j+1])],dp[i+1][1])];
				R[j+1]=rt[j+1][mex(rf[j+1][mex1(dp[i+1][j-1])],dp[i+1][m])];
				dp[i][j]=mex3(L[j-1],R[j+1],dp[i+1][j]);
			}
		}
		else{
			for(int j=0;j<=m+1;j++)L[j]=R[j]=0;

			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]=mex(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]=mex(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]);
			}
		}
	}
	int ans=0;
	// cout<<dp[1][1]<<endl;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j]=='B')ans=(ans^dp[i][j]);
		}
	}
	if(ans)cout<<"Alice\n";
	else cout<<"Bob\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7820kb

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7732kb

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7728kb

input:

5 18
#.#..#.#..###..###
##...#.#..#.#..#..
#....#.#..###..#..
##...#.#..#....#..
#.#..###..#....###

output:

Bob

result:

ok "Bob"

Test #5:

score: 0
Accepted
time: 0ms
memory: 8916kb

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: 14200kb

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: 7748kb

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: 2ms
memory: 13872kb

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: -100
Wrong Answer
time: 4ms
memory: 16088kb

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:

Alice

result:

wrong answer 1st words differ - expected: 'Bob', found: 'Alice'