QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235396#1811. How to Move the BeanslefyWA 9ms7920kbC++232.3kb2023-11-02 18:39:172023-11-02 18:39:17

Judging History

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

  • [2023-11-02 18:39:17]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:7920kb
  • [2023-11-02 18:39:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1010;
char a[N][N];
int n,m;
int get(vector<int>a){
	int vis[4];vis[0]=vis[1]=vis[2]=vis[3]=0;
	for(int x:a)if(x>=0&&x<=3)vis[x]=1;
	for(int i=0;i<4;i++)if(!vis[i])return i;
	return -1;
}
int sg[N][N],l[N],r[N],s[N],e[N];
int L1[N][5],L2[N][5],R1[N][5],R2[N][5];
void sol2(int i){
	for(int k=0;k<=3;k++)L1[1][k]=R1[m][k]=L2[m][k]=R2[1][k]=k;
	for(int j=2;j<=m;j++)for(int k=0;k<=3;k++){
		L1[j][k]=get({L1[j-1][k],sg[i+1][j]});
		R2[j][k]=R2[j-1][get({k,sg[i+1][j-1]})];
	}
	for(int j=m-1;j;j--)for(int k=0;k<=3;k++){
		L2[j][k]=L2[j+1][get({k,sg[i+1][j+1]})];
		R1[j][k]=get({R1[j+1][k],sg[i+1][j]});
	}
	for(int j=1;j<=m;j++){
		int L=-1,R=-1;
		if(m!=1){
			if(i!=m)L=L1[j-1][get({sg[i+1][1],L2[j+1][sg[i+1][j+1]]})];
			else L=L1[j-1][sg[i+1][1]];
			if(i!=1)R=R1[j+1][get({sg[i+1][m],R2[j-1][sg[i+1][j-1]]})];
			else R=R1[j+1][sg[i+1][m]];
		}
		sg[i][j]=get({L,R,sg[i+1][j]});
	}
}
void sol1(int i){
	int st=s[i],ed=e[i];
	for(int j=1;j<=m;j++)if(a[i][j]=='#')l[i]=r[i]=-1;
	for(int j=st+1;j<=m;j++)if(a[i][j]!='#'){
		l[j]=get({l[j-1],sg[i+1][j]});
	}
	if(a[i][1]!='#'){
		l[1]=get({l[m],sg[i+1][1]});
	}
	for(int j=2;j<st;j++)if(a[i][j]!='#'){
		l[j]=get({l[j-1],sg[i+1][j]});
	}
	for(int j=ed-1;j;j--)if(a[i][j]!='#'){
		r[j]=get({r[j+1],sg[i+1][j]});
	}
	if(a[i][m]!='#'){
		r[m]=get({r[1],sg[i+1][m]});
	}
	for(int j=m-1;j>ed;j--)if(a[i][j]!='#'){
		r[j]=get({r[j+1],sg[i+1][j]});
	}
	for(int j=1;j<=m;j++)if(a[i][j]!='#'){
		int le=j-1?j-1:m,ri=j+1<=m?j+1:1;
		sg[i][j]=get({sg[i+1][j],l[le],r[ri]});
	}
}
void solve(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
		int st=-1,ed=-1;
		for(int j=1;j<=m;j++){
			if(a[i][j]=='#'){
				if(st==-1)st=j;
				ed=j;
			}
		}
		s[i]=st,e[i]=ed;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)sg[i][j]=0;
		sg[i][0]=sg[i][m+1]=4;
	}
	for(int j=0;j<=m+1;j++)sg[n+1][j]=4;
	int ans=0;
	for(int i=n;i;i--){
		int st=s[i],ed=e[i];
		if(st!=-1)sol1(i);
		else sol2(i);
		for(int j=1;j<=m;j++)if(a[i][j]=='B')ans^=sg[i][j];
	}
	if(ans)printf("Alice\n");
	else printf("Bob\n");
}
int main(){
	// freopen("chequer.in","r",stdin);
	// freopen("chequer.out","w",stdout);
	// int t;
	// scanf("%d",&t);
	// while(t--)
	 solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

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

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

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

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

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

input:

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

output:

Bob

result:

ok "Bob"

Test #5:

score: 0
Accepted
time: 5ms
memory: 7920kb

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

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: 1ms
memory: 3648kb

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: 1ms
memory: 3968kb

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: 9ms
memory: 4752kb

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: 5ms
memory: 5056kb

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: 1ms
memory: 6300kb

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'