結果

問題 No.867 避難経路
ユーザー pekempeypekempey
提出日時 2019-08-16 22:53:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 172,636 KB
実行使用メモリ 77,080 KB
最終ジャッジ日時 2023-10-24 03:22:36
合計ジャッジ時間 49,593 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
76,932 KB
testcase_01 AC 26 ms
76,932 KB
testcase_02 AC 26 ms
76,932 KB
testcase_03 AC 27 ms
76,932 KB
testcase_04 AC 27 ms
76,932 KB
testcase_05 AC 26 ms
76,932 KB
testcase_06 AC 26 ms
76,932 KB
testcase_07 AC 27 ms
76,932 KB
testcase_08 AC 27 ms
76,932 KB
testcase_09 AC 27 ms
76,932 KB
testcase_10 AC 26 ms
76,932 KB
testcase_11 AC 27 ms
76,932 KB
testcase_12 AC 26 ms
76,932 KB
testcase_13 AC 26 ms
76,932 KB
testcase_14 AC 26 ms
76,932 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
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 26 ms
76,924 KB
testcase_42 AC 26 ms
76,924 KB
testcase_43 AC 27 ms
76,924 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[300][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, 300) 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, 300-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, 300) {
      ans = min(ans, dp[i][y][x] + (i+1) * k * k);
    }
    cout << ans << '\n';
  }
}
0