QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#236046 | #1811. How to Move the Beans | a_z_c | WA | 4ms | 7852kb | C++20 | 3.6kb | 2023-11-03 15:49:17 | 2023-11-03 15:49:17 |
Judging History
answer
// No mind to think.
//
// No will to break.
//
// No voice to cry suffering.
//
// Born of God and Void.
//
// You shall seal the blinding light that plagues their dreams.
//
// You are the Vessel.
//
// You are the Hollow Knight.
#ifdef N2
#define _GLIBCXX_DEBUG
#define LOG(...) fprintf(stderr, __VA_ARGS__)
#define DO(...) __VA_ARGS__
#define NDO(...)
#else
#define LOG(...)
#define DO(...)
#define NDO(...) __VA_ARGS__
#endif
#define syncoff ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int h, w;
int Mex(int x = -1, int y = -1, int z = -1) {
if(x != 0 && y != 0 && z != 0) return 0;
if(x != 1 && y != 1 && z != 1) return 1;
if(x != 2 && y != 2 && z != 2) return 2;
return 3;
}
int L[maxn], R[maxn], Lt[maxn][4], Rt[maxn][4], Lf[maxn][4], Rf[maxn][4];
int f[maxn][maxn];
bool emp[maxn][maxn];
int CalcL(int i, int j) {
if(!emp[i][j]) return -1;
if(~L[j]) return L[j];
int pre = j - 1 ? j - 1 : w;
return L[j] = Mex(f[i + 1][j], emp[i][pre] ? CalcL(i, pre) : -1);
}
int CalcR(int i, int j) {
if(!emp[i][j]) return -1;
if(~R[j]) return R[j];
int nxt = j % w + 1;
return R[j] = Mex(f[i + 1][j], emp[i][nxt] ? CalcR(i, nxt) : -1);
}
vector<pair<int, int>> bean;
int main() {
cin >> h >> w;
for(int i = 1; i <= h; i++) {
string in;
cin >> in;
for(int j = 1; j <= w; j++) {
switch(in[j - 1]) {
case '.':
emp[i][j] = true;
break;
case '#':
emp[i][j] = false;
break;
case 'B':
emp[i][j] = true;
bean.emplace_back(i, j);
break;
}
}
}
memset(f[h + 1], -1, sizeof(f[h + 1]));
for(int i = h; i; i--) {
if(w == 1) {f[i][1] = Mex(f[i + 1][1]); continue;}
memset(f[i], -1, sizeof(f[i]));
bool nod = true;
for(int j = 1; j <= w; j++) {
if(!emp[i][j]) {
nod = false;
break;
}
}
if(!nod) {
memset(L, -1, sizeof(L));
memset(R, -1, sizeof(R));
for(int j = 1; j <= w; j++) {
int pre = j - 1 ? j - 1 : w;
int nxt = j % w + 1;
if(emp[i][j]) f[i][j] = Mex(f[i + 1][j], CalcL(i, pre), CalcR(i, nxt));
}
continue;
}
for(int j = 1; j <= w; j++) for(int k = 0; k <= 3; k++) Lt[j][k] = (j == 1) ? k : Mex(Lt[j - 1][k], f[i + 1][j]);
for(int j = w; j; j--) for(int k = 0; k <= 3; k++) Rt[j][k] = (j == w) ? k : Mex(Rt[j + 1][k], f[i + 1][j]);
for(int j = w; j; j--) for(int k = 0; k <= 3; k++) Lf[j][k] = (j == w) ? k : Lf[j + 1][Mex(k, f[i + 1][j + 1])];
for(int j = 1; j <= w; j++) for(int k = 0; k <= 3; k++) Rf[j][k] = (j == 1) ? k : Rf[j - 1][Mex(k, f[i + 1][j - 1])];
f[i][1] = Mex(Lf[2][Mex(f[i + 1][2])], Rt[2][Mex(f[i + 1][w])], f[i + 1][1]);
f[i][w] = Mex(Rf[w - 1][Mex(f[i + 1][w - 1])], Lt[w - 1][Mex(f[i + 1][1])], f[i + 1][w]);
for(int j = 2; j < w; j++)
f[i][j] = Mex(f[i + 1][j], Lt[j - 1][Mex(f[i + 1][1], Lf[j + 1][Mex(f[i + 1][j + 1])])], Rt[j + 1][Mex(f[i + 1][w], Rf[j - 1][Mex(f[i + 1][j - 1])])]);
}
int ans = 0;
for(auto b : bean) {
ans ^= f[b.first][b.second];
}
LOG("%d\n", ans);
if(ans) cout << "Alice\n";
else cout << "Bob\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5860kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5576kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 4ms
memory: 5984kb
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: 5616kb
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: 7676kb
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: 5716kb
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: 6108kb
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: 2ms
memory: 7852kb
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: 5676kb
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'