QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19445 | #1811. How to Move the Beans | YaoBIG# | WA | 3ms | 3636kb | C++20 | 3.4kb | 2022-01-31 04:07:19 | 2022-05-06 05:22:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int H = 1000;
const int W = 1000;
const int N = 2*W;
string arr[H];
using bwp = pair<bitset<W>, bitset<W>>;
void sl(bitset<W>& bs, int w) {
int x = bs[0];
bs >>= 1;
bs[w - 1] = x;
}
void sr(bitset<W>& bs, int w) {
int x = bs[w - 1];
bs <<= 1;
bs[0] = x;
}
bwp pwMex(const bwp& b0, const bwp& b1) {
bitset<W> have_0 = b0.first | b1.first;
bitset<W> have_1 = b0.second | b1.second;
return {~have_0, have_0 & ~have_1};
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
for (int y = 0; y < h; ++y) cin >> arr[y];
bwp pre;
bitset<W> is_3;
is_3.set();
int grundy = 0;
for (int y = h-1; y >= 0; --y) {
int wall_x = -1;
for (int x = 0; x < w; ++x) {
if (arr[y][x] == '#') wall_x = x;
}
if (wall_x != -1) {
vector<int> dp_le(w, 3);
for (int x = wall_x + 1; x != wall_x; x = (x + 1) % w) {
if (arr[y][x] == '#') continue;
int pv = (x == 0 ? dp_le[w-1] : dp_le[x-1]);
int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
int v = 0;
while(v == pv || v == v2) ++v;
dp_le[x] = v;
}
vector<int> dp_ri(w, 3);
for (int x = (wall_x + w-1) % w; x != wall_x; x = (x + w-1) % w) {
if (arr[y][x] == '#') continue;
int pv = (x == w-1 ? dp_ri[0] : dp_ri[x+1]);
int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
int v = 0;
while(v == pv || v == v2) ++v;
dp_ri[x] = v;
}
for (int x = 0; x < w; ++x) {
if (arr[y][x] == '#') {
pre.first[x] = 0;
pre.second[x] = 0;
is_3[x] = 1;
} else {
int v0 = dp_le[(x + w-1) % w];
int v1 = dp_ri[(x + 1) % w];
int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
int v = 0;
while(v == v0 || v == v1 || v == v2) ++v;
if (arr[y][x] == 'B') grundy ^= v;
is_3[x] = (v == 3);
pre.first[x] = (v == 0);
pre.second[x] = (v == 1);
// cerr << y << ' ' << x << ": " << v0 << ' ' << v1 << ' ' << v2 << " -> " << v << '\n';
}
}
} else {
bwp le;
for (int i = 0; i < w; ++i) {
le = pwMex(le, pre);
sl(le.first, w);
sl(le.second, w);
/*
cerr << "le after " << i << ": ";
for (int x = 0; x < w; ++x) cerr << le.first[x] << le.second[x] << ' ';
cerr << '\n';
*/
}
bwp ri;
for (int i = 0; i < w; ++i) {
ri = pwMex(ri, pre);
sr(ri.first, w);
sr(ri.second, w);
/*
cerr << "ri after " << i << ": ";
for (int x = 0; x < w; ++x) cerr << ri.first[x] << ri.second[x] << ' ';
cerr << '\n';
*/
}
for (int x = 0; x < w; ++x) {
int v0 = (1 - le.first[x]) + (1 - (le.first[x] || le.second[x]));
int v1 = (1 - ri.first[x]) + (1 - (ri.first[x] || ri.second[x]));
int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
int v = 0;
while(v == v0 || v == v1 || v == v2) ++v;
if (arr[y][x] == 'B') grundy ^= v;
is_3[x] = (v == 3);
pre.first[x] = (v == 0);
pre.second[x] = (v == 1);
// cerr << y << ' ' << x << ": " << v0 << ' ' << v1 << ' ' << v2 << " -> " << v << '\n';
}
}
}
cout << ((grundy == 0) ? "Bob" : "Alice") << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3636kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3604kb
input:
1 1 B
output:
Alice
result:
wrong answer 1st words differ - expected: 'Bob', found: 'Alice'