QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232268 | #1811. How to Move the Beans | JWRuixi | WA | 4ms | 14696kb | C++20 | 3.1kb | 2023-10-30 09:01:26 | 2023-10-30 09:01:27 |
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[4];
Node (int o = 0) { iota(g, g + 4, 0); }
int& operator [] (const int &i) {
return g[i];
}
Node operator * (const Node &rhs) const {
Node r;
for (int i = 0; i < 4; 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;
if (i < m - 1) r = r * sf[i + 1];
if (i > 0) r = r * pr[i - 1];
L[o][i] = r[3];
}
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;
if (i > 0) r = r * pr[i - 1];
if (i < m - 1) r = r * sf[i + 1];
R[o][i] = r[3];
}
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: 7772kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7780kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 7780kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7816kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 2ms
memory: 8972kb
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: 8288kb
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: 9964kb
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: 7952kb
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: 4ms
memory: 8700kb
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: 4ms
memory: 14696kb
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'