QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236028#1811. How to Move the BeansdieselhuangWA 10ms8600kbC++142.5kb2023-11-03 15:31:072023-11-03 15:31:08

Judging History

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

  • [2023-11-03 15:31:08]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:8600kb
  • [2023-11-03 15:31:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0, mex[4][4][4], f[1010][1010], fl[1010], fr[1010], gl[1010][3], gr[1010][3], hl[1010][3], hr[1010][3];
char a[1010][1010];
int main()
{
	int i, j, p;
	for(i = 0; i <= 3; i++){
		for(j = 0; j <= 3; j++){
			for(p = 0; p <= 3; p++){
				if(i != 0 && j != 0 && p != 0) mex[i][j][p] = 0;
				else if(i != 1 && j != 1 && p != 1) mex[i][j][p] = 1;
				else if(i != 2 && j != 2 && p != 2) mex[i][j][p] = 2;
				else mex[i][j][p] = 3;
			}
		}
	}
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; i++){
		scanf("%s", a[i] + 1);
	}
	if(m == 1){
		f[n + 1][1] = 3;
		for(i = n; i >= 1; i--){
			if(a[i][1] == '#') f[i][1] = 3;
			else f[i][1] = mex[f[i + 1][1]][3][3];
			if(a[i][1] == 'B') ans ^= f[i][1];
		}
		if(ans > 0) printf("Alice");
		else printf("Bob");
		return 0;
	}
	for(i = 1; i <= m; i++) f[n + 1][i] = 3;
	for(i = n; i >= 1; i--){
		for(j = 1; j <= m; j++){
			if(a[i][j] == '#') break;
		}
		if(j <= m){
			for(p = 1; p <= m; p++){
				if(a[i][p] == '#') fl[p] = 3, fr[p] = 3, f[i][p] = 3;
			}
			for(p = j; p <= m; p++){
				if(a[i][p] != '#') fl[p] = mex[fl[p - 1]][f[i + 1][p]][3];
			}
			fl[0] = fl[m];
			for(p = 1; p < j; p++){
				if(a[i][p] != '#') fl[p] = mex[fl[p - 1]][f[i + 1][p]][3];
			}
			for(p = j; p >= 1; p--){
				if(a[i][p] != '#') fr[p] = mex[fr[p + 1]][f[i + 1][p]][3];
			}
			fr[m + 1] = fr[1];
			for(p = m; p > j; p--){
				if(a[i][p] != '#') fr[p] = mex[fr[p + 1]][f[i + 1][p]][3];
			}
		}else{
			for(j = 0; j < 3; j++){
				gl[1][j] = j; gr[m][j] = j; hl[1][j] = j; hr[m][j] = j;
				gl[0][j] = j; gr[m + 1][j] = j; hl[0][j] = j; hr[m + 1][j] = j;
				for(p = 2; p <= m; p++) gl[p][j] = mex[gl[p - 1][j]][f[i + 1][p]][3];
				for(p = m - 1; p >= 1; p--) gr[p][j] = mex[gr[p + 1][j]][f[i + 1][p]][3];
			}
			for(p = 2; p <= m; p++){
				for(j = 0; j < 3; j++) hl[p][j] = hl[p - 1][mex[f[i + 1][p - 1]][j][3]];
			}
			for(p = m - 1; p >= 1; p--){
				for(j = 0; j < 3; j++) hr[p][j] = hr[p + 1][mex[f[i + 1][p + 1]][j][3]];
			}
			f[i + 1][0] = f[i + 1][m]; f[i + 1][m + 1] = f[i + 1][1]; 
			for(p = 1; p <= m; p++){
				fl[p] = gl[p - 1][mex[hr[p - 1][mex[f[i + 1][p + 1]][3][3]]][f[i + 1][1]][3]];
				fr[p] = gr[p + 1][mex[hl[p + 1][mex[f[i + 1][p - 1]][3][3]]][f[i + 1][m]][3]];
			}
		}
		for(j = 1; j <= m; j++){
			if(a[i][j] != '#') f[i][j] = mex[fl[(j + m - 2) % m + 1]][fr[j % m + 1]][f[i + 1][j]];
			if(a[i][j] == 'B') ans ^= f[i][j];
		}
	}
	if(ans > 0) printf("Alice");
	else printf("Bob");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

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

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

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

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

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

input:

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

output:

Bob

result:

ok "Bob"

Test #5:

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

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

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

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

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

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

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: 0
Accepted
time: 1ms
memory: 6156kb

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:

Alice

result:

ok "Alice"

Test #12:

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

input:

196 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
...

output:

Bob

result:

ok "Bob"

Test #13:

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

input:

148 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

output:

Alice

result:

ok "Alice"

Test #14:

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

input:

2 5
...#.
.#B..

output:

Alice

result:

ok "Alice"

Test #15:

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

input:

2 4
B..B
....

output:

Bob

result:

ok "Bob"

Test #16:

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

input:

8 1
.
B
.
.
.
B
.
.

output:

Bob

result:

ok "Bob"

Test #17:

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

input:

803 520
BBB#...B.BBB.BBBB#.#BBB.#BBB.BBB.BB.BB..B#BBB##.#BB.#BBBB.BB#BB.###BBBBB.BBBBB.#.BBBBBB#BBB#.B.BB.####BBBB...#.BBBBBBBB#BBB#BBB##B#B..#BBB.BB#.BBBBB#.BB#B..BBBB.BBBB.BB.BBBBB##B#BB.BB#B##B#BBBBB.BBBBBB#BBB##BBBBB##B.B.BBB.B.BBBBB#B#BB.BBBBBB..#B.##BB...B.B.BBBBB..BB.B.##BBBB#B#..#BBBBBBBBBB#...

output:

Alice

result:

ok "Alice"

Test #18:

score: 0
Accepted
time: 10ms
memory: 8600kb

input:

713 987
B.BB#.BBB#B#BB#BBBBBBB##.BBB..B#..B..BBBBBBBB#BB#BB..BB..##BBBBBBB#BBBBB.#BBBBB#B..BBBBBB.BB#B#BBBBBB#BB.B#BB#B..B#B.B#.B#BB.BB.BBBBB.BB#B#B#B.B##BB##B#BB##..#BB#.B.B.#.B#BB.BBBBBBB#BBBB.#.B.#BBB#BB.BBBB.B...B##B..#BB.BBBB.##..#B.B##BBBB.B#BBB##.B#BB.BB..BB#B.BB.#..#.#BB#B#..BBBBBBB.BBBB.B#B...

output:

Alice

result:

ok "Alice"

Test #19:

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

input:

103 515
#B#BB..BB.BBB#BB#..BB.#BBBBBB.###B#BB##BBB#BBBBBB.B.BBBB##BBB#BBB...###BBBBBBB.BBBBB.BBB.B#B.#B..BB..BBBB#.#BB#B.B#BB#B#..B.B.B#.BBB..B#.BB##.BBB#B##BB.B.#BBBBBB#BBBBB.BBB#.BB#.B.BBBBBBB...B.BB..B..BB##BBBB##B#.BB.B..#B.BB.##B.BBBB#BBBBBBB####BBB#BB#BBBBBB#B#B##BBB.B#B.B.##B...BBBB#BBBBB#BB#...

output:

Alice

result:

ok "Alice"

Test #20:

score: -100
Wrong Answer
time: 0ms
memory: 3976kb

input:

21 144
BBBBBB.BBBBBBBBBBB.BBBBB..BBB.B..BBBBBB.BBBBBBBB.BBBBBBB.BBBBBBBBBBBB.BB.BBBBB.BB.BBBB.BBBBB.B.BBBBBBBBB.B.BBBB.BBBBBBBBBBB.BBB.B.BB.BBBBBBB..BB
BBB.B.BBBBB.##BBB.B##..BB..BBBBBBBB#B.BB.B..BBBB#.B.#BBB...B.BB#BBBBBB#B.BBBBBB.B.BBB#BB..BBBB.#.B#BBB#BB#B..B#BBB#B.B##B.B#.##B.BB#B#B.B...B.BB
B.B...

output:

Bob

result:

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