QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608451 | #9224. Express Eviction | maxplus | WA | 1ms | 3832kb | C++20 | 2.1kb | 2024-10-03 22:00:21 | 2024-10-03 22:00:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 64;
bool b[N][N];
int c[N][N], d[N][N], p[N * N], h, w;
int chk(int i, int j) { return i >= 0 && j >= 0 && i <= h && j <= w; }
int get(int i, int j) { return chk(i, j) && b[i][j]; }
int getp(int v) { return p[v] == v? v: p[v] = getp(p[v]); }
void uni(int u, int v) { p[getp(v)] = getp(u); }
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> h >> w;
for (int i = 0; i < h; ++i) if (string s; cin >> s, 1)
for (int j = 0; j < w; ++j) b[i][j] = s[j] == '#';
fill(d[0] + 1, d[N], 1e9);
iota(p, end(p), 0);
for (int i = 0; i <= h; ++i)
for (int j = 0; j <= w; ++j)
for (auto di: {-1, 0})
for (auto dj: {-1, 0}) c[i][j] += get(i + di, j + dj);
for (int i = 0; i <= h; ++i)
for (int j = 0; j <= w; ++j) if (!c[i][j]) {
if (i && !c[i - 1][j]) uni(i * N + j, i * N + j - N);
if (j && !c[i][j - 1]) uni(i * N + j, i * N + j - 1);
}
priority_queue pq{greater{}, vector<int>{{}}};
array<int, 4> ta[2];
while (pq.size()) {
auto t = pq.top(); pq.pop();
int cd = t >> 12, i = t >> 6 & 63, j = t & 63;
if (cd != d[i][j]) continue;
for (auto di: {-1, 0, 1})
for (auto dj: {-1, 0, 1}) if (!chk(i + di, j + dj)); else if (!di ^ !dj)
if (auto t = cd + get(i + di - (di < 1), j + dj - (dj < 1)) + get(i + di - (di < 0), j + dj - (dj < 0)); d[i + di][j + dj] > t) {
pq.push((d[i + di][j + dj] = t) << 12 | i + di << 6 | j + dj);
} else; else if (di && d[i + di][j + dj] > cd + c[i + di][j + dj] - b[i][j]) {
ta[0] = ta[1] = {-1, -1, -1, -1};
for (int w: {0, 1}) if (int p = 0; 1)
for (int ddi: {0, 1, 2})
for (int ddj: {0, 1, 2}) if ((ddi == 2) ^ (ddj == 2)) if (int ni = i + di * (w? ddi + 1: -ddi), nj = j + dj * (w? ddj + 1: -ddj); chk(ni, nj) && !c[ni][nj]) {
ta[w][p++] = getp(ni * N + nj);
}
bool ok = 0;
for (auto& a: ta[0]) if (~a)
for (auto& b: ta[1]) ok |= a == b;
if (ok) pq.push((d[i + di][j + dj] = cd + c[i + di][j + dj] - b[i][j]) << 12 | i + di << 6 | j + dj);
}
}
cout << d[h][w] + b[0][0];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3576kb
input:
35 35 ....###########...#########........ ##..#######################..#####. ....#######################..#####. ...#.....##################..#####. .##......##################.....##. .##..##..#############.....#....##. .....##..#############......##..##. ....#....#############..##..##..##. ####.....
output:
21
result:
wrong answer 1st numbers differ - expected: '16', found: '21'