QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235232#1811. How to Move the Beansc20230507WA 2ms18040kbC++142.7kb2023-11-02 16:16:292023-11-02 16:16:29

Judging History

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

  • [2023-11-02 16:16:29]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:18040kb
  • [2023-11-02 16:16:29]
  • 提交

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=lt[j-1][mex2(dp[i+1][1],lf[j+1][mex(dp[i+1][j+1])])];
					int v2=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]);
					}
				}
				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#.

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7804kb

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

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

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

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

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

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

input:

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

output:

Bob

result:

ok "Bob"

Test #5:

score: 0
Accepted
time: 2ms
memory: 8076kb

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

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

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

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: 0ms
memory: 18040kb

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

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:

Bob

result:

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