結果

問題 No.34 砂漠の行商人
ユーザー nebukuro09nebukuro09
提出日時 2016-12-07 14:50:53
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2,022 ms / 5,000 ms
コード長 1,164 bytes
コンパイル時間 1,206 ms
コンパイル使用メモリ 100,196 KB
実行使用メモリ 326,416 KB
最終ジャッジ日時 2023-09-02 23:21:25
合計ジャッジ時間 28,150 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 7 ms
4,400 KB
testcase_02 AC 87 ms
18,792 KB
testcase_03 AC 70 ms
16,992 KB
testcase_04 AC 541 ms
85,920 KB
testcase_05 AC 707 ms
100,600 KB
testcase_06 AC 363 ms
76,224 KB
testcase_07 AC 1,066 ms
172,560 KB
testcase_08 AC 1,434 ms
198,848 KB
testcase_09 AC 1,200 ms
182,592 KB
testcase_10 AC 1,409 ms
326,188 KB
testcase_11 AC 1,395 ms
326,416 KB
testcase_12 AC 534 ms
89,108 KB
testcase_13 AC 2,014 ms
325,732 KB
testcase_14 AC 1,872 ms
319,804 KB
testcase_15 AC 577 ms
93,468 KB
testcase_16 AC 527 ms
90,308 KB
testcase_17 AC 1,139 ms
181,240 KB
testcase_18 AC 118 ms
25,716 KB
testcase_19 AC 1,906 ms
310,352 KB
testcase_20 AC 1,897 ms
316,736 KB
testcase_21 AC 2,022 ms
322,368 KB
testcase_22 AC 1,731 ms
300,440 KB
testcase_23 AC 833 ms
107,800 KB
testcase_24 AC 1,881 ms
310,976 KB
testcase_25 AC 1,073 ms
176,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import core.bitop;


void main() {
  auto s = readln.split.map!(to!int);
  auto N = s[0];
  auto V = s[1];
  auto Sc = s[2]-1;
  auto Sr = s[3]-1;
  auto Gc = s[4]-1;
  auto Gr = s[5]-1;
  auto B = iota(N).map!(_ => readln.split.map!(to!int).array).array;
  auto dp = new int[][][](6000, N, N);
  int[] dr = [0, 0, -1, 1];
  int[] dc = [-1, 1, 0, 0];
  int INF = 10^^9;

  foreach (k; 0..6000)
    foreach (i; 0..N)
      foreach (j; 0..N)
        dp[k][i][j] = (i == Sr && j == Sc) ? 0 : INF;

  foreach (k; 1..6000)
    foreach (i; 0..N)
      foreach (j; 0..N) {
        if (abs(Sr-i) + abs(Sc-j) > k) continue;
        foreach (d; 0..4) {
          auto nr = i + dr[d];
          auto nc = j + dc[d];
          if (nr >= 0 && nr < N && nc >= 0 && nc < N)
            dp[k][i][j] = min(dp[k][i][j], dp[k-1][nr][nc]+B[i][j]);
        }
      }

  foreach (k; 0..6000)
    if (dp[k][Gr][Gc] < V) {
      k.writeln;
      return;
    }
  writeln(-1);
}
0