QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#608144 | #9224. Express Eviction | maxplus | WA | 1ms | 3644kb | C++20 | 988b | 2024-10-03 19:05:43 | 2024-10-03 19:05:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 64;
bool b[N][N];
int d[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 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);
priority_queue pq{greater{}, vector<int>{{}}};
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 ((!di ^ !dj) && chk(i + di, j + 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);
}
}
cout << d[h][w];
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
12
result:
wrong answer 1st numbers differ - expected: '11', found: '12'