QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608144#9224. Express EvictionmaxplusWA 1ms3644kbC++20988b2024-10-03 19:05:432024-10-03 19:05:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 19:05:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3644kb
  • [2024-10-03 19:05:43]
  • 提交

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'