QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232236 | #1811. How to Move the Beans | JWRuixi | WA | 36ms | 15480kb | C++20 | 3.2kb | 2023-10-30 08:07:53 | 2023-10-30 08:07:54 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,avx2")
// #define ATC
#define LL long long
#define eb emplace_back
#define FIO(FILENAME) freopen(FILENAME".in", "r", stdin), freopen(FILENAME".out", "w", stdout)
using namespace std;
#ifdef ATC
#include <atcoder/all>
using namespace atcoder;
#endif
constexpr int N = 1007;
int n, m, L[N][N], R[N][N], f[N][N];
string s[N];
inline int mex (vector<int> v) {
bitset<7> s;
for (int x : v) s.set(x);
int r = 0;
while (s[r]) ++r;
return r;
}
inline int gtn (int i) {
int r = i + 1;
return r >= m ? 0 : r;
}
inline int gtp (int i) {
int r = i - 1;
return r < 0 ? m - 1 : r;
}
namespace BF1 {
void main (int o) {
int p = s[o].find('#');
int i = p;
do {
int r = gtn(i);
while (s[o][r] != '#' && r != p) r = gtn(r);
for (int j = gtn(i); j != r; j = gtn(j)) L[o][j] = mex({L[o][gtp(j)], f[o + 1][j]});
for (int j = gtp(r); j != i; j = gtp(j)) R[o][j] = mex({R[o][gtn(j)], f[o + 1][j]});
i = r;
} while (i != p);
for (int j = 0; j < m; j++) {
if (s[o][j] != '#') {
f[o][j] = mex({L[o][gtp(j)], R[o][gtn(j)], f[o + 1][j]});
}
}
}
}
namespace BF2 {
struct Node {
int g[3];
Node (int o = 0) { g[0] = g[1] = g[2] = o; }
Node operator * (const Node &rhs) const {
Node r;
for (int i = 0; i < 3; i++) r.g[i] = rhs.g[g[i]];
return r;
}
} a[N], pr[N], sf[N];
void main (int o) {
if (m == 1) {
f[o][0] = mex({f[o + 1][0]});
return;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 3; j++) {
a[i].g[j] = mex({f[o + 1][i], j});
}
}
pr[0] = a[0];
for (int i = 1; i < m; i++) pr[i] = pr[i - 1] * a[i];
sf[m - 1] = a[m - 1];
for (int i = m - 2; ~i; i--) sf[i] = a[i] * sf[i + 1];
for (int i = 0; i < m; i++) {
Node r;
for (int j = 0; j < 3; j++) r.g[j] = j;
if (i < m - 1) r = r * sf[i + 1];
if (i > 1) r = r * pr[i - 2];
R[o][gtp(i)] = r.g[mex({f[o + 1][i]})];
}
pr[0] = a[0];
for (int i = 1; i < m; i++) pr[i] = a[i] * pr[i - 1];
sf[m - 1] = a[m - 1];
for (int i = m - 2; ~i; i--) sf[i] = sf[i + 1] * a[i];
for (int i = 0; i < m; i++) {
Node r;
for (int j = 0; j < 3; j++) r.g[j] = j;
if (i > 0) r = r * pr[i - 1];
if (i < m - 2) r = r * sf[i + 2];
L[o][gtn(i)] = r.g[mex({f[o + 1][i]})];
}
for (int j = 0; j < m; j++) {
f[o][j] = mex({f[o + 1][j], L[o][j], R[o][j]});
}
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < m; i++) f[n][i] = L[n][i] = R[n][i] = 6;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '#') {
f[i][j] = L[i][j] = R[i][j] = 6;
}
}
}
for (int i = n - 1; ~i; i--) {
if (s[i].find('#') == s[i].npos) {
BF2::main(i);
} else {
BF1::main(i);
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) {
// cout << f[i][j] << " \n"[j == m - 1];
// }
// }
unsigned r = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == 'B') {
r ^= f[i][j];
}
}
}
puts(r ? "Alice" : "Bob");
}
// I love WHQ!
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7996kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7660kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7760kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7788kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 0ms
memory: 14596kb
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: 8052kb
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: 7920kb
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: 8144kb
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: 3ms
memory: 14544kb
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: 3ms
memory: 14036kb
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: 8196kb
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: 1ms
memory: 8552kb
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: 8348kb
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: 1ms
memory: 7772kb
input:
2 5 ...#. .#B..
output:
Alice
result:
ok "Alice"
Test #15:
score: 0
Accepted
time: 1ms
memory: 7992kb
input:
2 4 B..B ....
output:
Bob
result:
ok "Bob"
Test #16:
score: 0
Accepted
time: 1ms
memory: 9748kb
input:
8 1 . B . . . B . .
output:
Bob
result:
ok "Bob"
Test #17:
score: 0
Accepted
time: 23ms
memory: 15464kb
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: 36ms
memory: 15480kb
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: 4ms
memory: 10296kb
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: 0
Accepted
time: 1ms
memory: 7848kb
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:
Alice
result:
ok "Alice"
Test #21:
score: -100
Wrong Answer
time: 10ms
memory: 8876kb
input:
245 501 B.BBBBBBB.B.BB.BBB.BB.BBBBBBBBBBB.BB.BBBBBBBBBBBBB.BB.BBBBBBB.BBBBBB.BBB.B.BBB.BBBBBBBB..BBB..BB.BBBBB.BBB.BBBBB.BBBB..BBBBB.BBB.BBBBB.BBBBBBBB.BBB.BBBBB.BBBBBBBBBBBBBBBB.BBBBBBBB.BBB.BBB.BB...BBB.B.BBBB.BBB.B.BB.BBBBBBBBBBBBBBBBB.BBBBB.BBBBBBB.BBB.B.B..BB.BBBB..BBBBBB.BBB..BB.BBB.BB.BBB.BB....
output:
Alice
result:
wrong answer 1st words differ - expected: 'Bob', found: 'Alice'