結果

問題 No.867 避難経路
ユーザー pekempeypekempey
提出日時 2019-08-16 23:04:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,097 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 172,644 KB
実行使用メモリ 125,888 KB
最終ジャッジ日時 2023-10-24 04:28:58
合計ジャッジ時間 79,683 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
125,672 KB
testcase_01 AC 42 ms
125,672 KB
testcase_02 AC 41 ms
125,672 KB
testcase_03 AC 41 ms
125,672 KB
testcase_04 AC 42 ms
125,672 KB
testcase_05 AC 41 ms
125,672 KB
testcase_06 AC 41 ms
125,672 KB
testcase_07 AC 42 ms
125,672 KB
testcase_08 AC 42 ms
125,672 KB
testcase_09 AC 41 ms
125,672 KB
testcase_10 AC 41 ms
125,672 KB
testcase_11 AC 41 ms
125,672 KB
testcase_12 AC 42 ms
125,672 KB
testcase_13 AC 42 ms
125,672 KB
testcase_14 AC 42 ms
125,672 KB
testcase_15 AC 3,849 ms
125,812 KB
testcase_16 AC 3,830 ms
125,812 KB
testcase_17 AC 3,862 ms
125,812 KB
testcase_18 AC 3,844 ms
125,812 KB
testcase_19 AC 3,819 ms
125,812 KB
testcase_20 AC 3,873 ms
125,812 KB
testcase_21 AC 3,786 ms
125,812 KB
testcase_22 AC 3,834 ms
125,812 KB
testcase_23 AC 3,842 ms
125,812 KB
testcase_24 AC 3,835 ms
125,812 KB
testcase_25 AC 3,860 ms
125,812 KB
testcase_26 AC 3,894 ms
125,812 KB
testcase_27 AC 3,893 ms
125,812 KB
testcase_28 AC 3,898 ms
125,808 KB
testcase_29 AC 3,918 ms
125,808 KB
testcase_30 AC 1,044 ms
125,808 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,025 ms
125,808 KB
testcase_35 AC 1,071 ms
125,808 KB
testcase_36 AC 996 ms
125,808 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 40 ms
125,660 KB
testcase_42 AC 41 ms
125,660 KB
testcase_43 AC 40 ms
125,660 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[500][250][250];

constexpr int inf = 1e9;

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, 500) rep(i, 250) rep(j, 250) dp[k][i][j] = inf;
  dp[0][GY][GX] = A[GY][GX];
  const int dy[] = {0, 1, 0, -1};
  const int dx[] = {1, 0, -1, 0};
  rep(k, 500-1) {
    rep(i, H) rep(j, W) {
      rep(l, 4) {
        int ni = i + dy[l];
        int nj = j + dx[l];
        if (0 <= ni && ni < H && 0 <= nj && nj < W) {
          dp[k+1][ni][nj] = min(dp[k+1][ni][nj], dp[k][i][j] + A[ni][nj]);
        }
      }
    }
  }
  int Q; cin >> Q;
  while (Q--) {
    int y, x;
    ll k; cin >> y >> x >> k; y--; x--;
    ll ans = 1e18;
    rep(i, 500) if (dp[i][y][x] != inf) {
      ans = min(ans, dp[i][y][x] + (i+1) * k * k);
    }

    cout << ans << '\n';
  }
}
0