結果

問題 No.867 避難経路
ユーザー pekempeypekempey
提出日時 2019-08-16 23:27:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,075 bytes
コンパイル時間 5,021 ms
コンパイル使用メモリ 182,852 KB
実行使用メモリ 16,704 KB
最終ジャッジ日時 2023-10-24 05:46:53
合計ジャッジ時間 20,084 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
16,360 KB
testcase_01 AC 6 ms
16,360 KB
testcase_02 AC 5 ms
16,360 KB
testcase_03 AC 6 ms
16,360 KB
testcase_04 AC 6 ms
16,360 KB
testcase_05 AC 6 ms
16,360 KB
testcase_06 AC 7 ms
16,360 KB
testcase_07 AC 7 ms
16,360 KB
testcase_08 AC 7 ms
16,360 KB
testcase_09 AC 6 ms
16,360 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 533 ms
16,640 KB
testcase_21 AC 517 ms
16,640 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 6 ms
16,352 KB
testcase_42 AC 6 ms
16,352 KB
testcase_43 AC 6 ms
16,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int dp[50][250][250];
ll ep[250][250];

constexpr ll inf = 1e13;

void chmin(ll &x, ll y) {
  x = min(x, y);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int H, W, GY, GX; cin >> H >> W >> GY >> GX;
  GY--; GX--;
  vector<vector<int>> A(H, vector<int>(W));
  rep(i, H) rep(j, W) cin >> A[i][j];
  rep(k, 50) rep(i, 250) rep(j, 250) dp[k][i][j] = 1e9;
  dp[0][GY][GX] = A[GY][GX];
  const int dy[] = {0, 1, 0, -1};
  const int dx[] = {1, 0, -1, 0};
  rep(k, 50) {
    dp[k][GY][GX] = A[GY][GX] + k*k;
    priority_queue<tuple<ll, int, int>> q;
    q.emplace(-dp[k][GY][GX], GY, GX);
    while (!q.empty()) {
      ll d;
      int y, x;
      tie(d, y, x) = q.top(); q.pop();
      if (-d > dp[k][y][x]) continue;
      rep(l, 4) {
        int ny = y + dy[l];
        int nx = x + dx[l];
        if (0 <= ny && ny < H && 0 <= nx && nx < W) {
          if (dp[k][ny][nx] > dp[k][y][x] + A[ny][nx] + k*k) {
            dp[k][ny][nx] = dp[k][y][x] + A[ny][nx] + k*k;
            q.emplace(-dp[k][ny][nx], ny, nx);
          }
        }
      }
    }
  }
  ep[GY][GX] = A[GY][GX] + inf;
  rep(i, 250) rep(j, 250) ep[i][j] = 1e18;
  priority_queue<tuple<ll, int, int>> q;
  q.emplace(-ep[GY][GX], GY, GX);
  while (!q.empty()) {
    ll d;
    int y, x;
    tie(d, y, x) = q.top(); q.pop();
    if (-d > ep[y][x]) continue;
    rep(l, 4) {
      int ny = y + dy[l];
      int nx = x + dx[l];
      if (0 <= ny && ny < H && 0 <= nx && nx < W) {
        if (ep[ny][nx] > ep[y][x] + A[ny][nx] + inf) {
          ep[ny][nx] = ep[y][x] + A[ny][nx] + inf;
          q.emplace(-ep[ny][nx], ny, nx);
        }
      }
    }
  }
  int Q; cin >> Q;
  while (Q--) {
    int y, x;
    ll k; cin >> y >> x >> k; y--; x--;
    if (k < 50) {
      cout << dp[k][y][x] << '\n';
    } else {
      ll d = (abs(GY - y) + abs(GX - x) + 1);
      cout << ep[y][x] - d * inf + d * k * k << '\n';
    }
  }
}
0