QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232230 | #1811. How to Move the Beans | JWRuixi | WA | 4ms | 14580kb | C++20 | 2.9kb | 2023-10-30 07:56:50 | 2023-10-30 07:56:50 |
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);
}
}
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) {
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]})];
}
}
}
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 j = 0; j < m; j++) f[i][j] = max(L[i][j], R[i][j]);
}
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!
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7720kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7780kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9684kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 4ms
memory: 14580kb
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: 13928kb
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: -100
Wrong Answer
time: 1ms
memory: 7888kb
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:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'