結果

問題 No.34 砂漠の行商人
ユーザー letrangerjpletrangerjp
提出日時 2017-06-13 21:30:17
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 20,856 KB
最終ジャッジ日時 2023-10-24 21:52:16
合計ジャッジ時間 22,551 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 WA -
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, V, SX, SY, GX, GY = gets.split.take(6).map(&:to_i)
MAP = N.times.map{ gets.split.take(N).map(&:to_i) }
p MAP


def f(start, last)
  visited = N.times.map{[-1]*N}
  visited[start[0]][start[1]] = V
  q = [[0, V] + start]

  res = -1
  while !q.empty?
    step, hp, x, y = q.shift
    if [x, y] == last
      res = step
      break
    end
    [[x+1, y], [x-1, y], [x, y+1], [x, y-1]].each{|a, b|
      next if !a.between?(0, N-1)
      next if !b.between?(0, N-1)
      _hp = hp - MAP[b][a]
      next if _hp < 1
      _step = step + 1
      if visited[a][b] < _hp
        visited[a][b] = _hp
        elem = [_step, _hp, a, b]
        # q[q.bsearch_index{|v|(v <=> elem) < 0}||q.size, 0] = [elem]
        q << elem
      end
    }
  end
  res
end

p f([SX-1, SY-1], [GX-1, GY-1])
0