結果

問題 No.34 砂漠の行商人
ユーザー nebukuro09nebukuro09
提出日時 2016-11-10 11:03:05
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,269 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 107,240 KB
実行使用メモリ 813,532 KB
最終ジャッジ日時 2023-09-02 22:48:22
合計ジャッジ時間 7,146 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 WA -
testcase_03 AC 99 ms
15,264 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

void main() {
  int INF = 10^^5;
  alias Tuple!(int, "depth", int, "row", int, "col", int, "v") node;
  
  auto input = readln.split.map!(to!int);
  int N = input[0];
  int V = input[1];
  int Sr = input[3]-1;
  int Sc = input[2]-1;
  int Gr = input[5]-1;
  int Gc = input[4]-1;
  auto B = iota(N).map!(_ => readln.split.map!(to!int).array).array;

  int[4] dr = [0, 0, 1, -1];
  int[4] dc = [1, -1, 0, 0];
  auto dist = iota(N).map!(_ => iota(N).map!(_ => INF).array).array;
  DList!node queue;
  queue.insert(node(0, Sr, Sc, V));

  while (!queue.empty) {
    auto n = queue.front;
    queue.removeFront;
    if (n.depth > dist[n.row][n.col])
      continue;
    dist[n.row][n.col] = n.depth;

    foreach (i; 0..4) {
      int nr = n.row + dr[i];
      int nc = n.col + dc[i];
      if (nr < 0 || nr >= N || nc < 0 || nc >= N)
        continue;
      if (n.depth+1 > dist[nr][nc])
        continue;
      if (n.v - B[nr][nc] <= 0)
        continue;
      queue.insert(node(n.depth+1, nr, nc, n.v-B[nr][nc]));
    }
  }

  writeln(dist[Gr][Gc] == INF ? -1 : dist[Gr][Gc]);
}
0