結果

問題 No.34 砂漠の行商人
ユーザー letrangerjpletrangerjp
提出日時 2017-06-13 22:42:51
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 710 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 11,884 KB
実行使用メモリ 17,424 KB
最終ジャッジ日時 2023-10-24 21:53:44
合計ジャッジ時間 5,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
16,056 KB
testcase_01 AC 84 ms
16,056 KB
testcase_02 AC 88 ms
16,192 KB
testcase_03 AC 78 ms
16,056 KB
testcase_04 WA -
testcase_05 AC 148 ms
16,552 KB
testcase_06 AC 117 ms
16,384 KB
testcase_07 AC 231 ms
16,644 KB
testcase_08 AC 260 ms
16,840 KB
testcase_09 AC 206 ms
16,660 KB
testcase_10 AC 122 ms
16,708 KB
testcase_11 AC 165 ms
17,304 KB
testcase_12 AC 96 ms
16,252 KB
testcase_13 AC 462 ms
17,424 KB
testcase_14 AC 465 ms
17,412 KB
testcase_15 AC 84 ms
16,184 KB
testcase_16 AC 120 ms
16,404 KB
testcase_17 AC 81 ms
16,196 KB
testcase_18 AC 86 ms
16,192 KB
testcase_19 AC 234 ms
17,072 KB
testcase_20 AC 329 ms
17,424 KB
testcase_21 AC 86 ms
16,384 KB
testcase_22 AC 92 ms
16,356 KB
testcase_23 AC 83 ms
16,188 KB
testcase_24 AC 367 ms
17,396 KB
testcase_25 AC 117 ms
16,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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) }
MAX_DMG = MAP.map{|y|y.max}.max

def f(start, last)
  visited = Hash.new 0
  visited[start] = V
  q = Hash.new 0
  q[start] = V

  step = -1
  while !q.empty?
    step += 1
    qq = {}
    q.each{|(x,y), hp|
      [[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
        return step if [x, y] == last
        if visited[[a,b]] < _hp
          visited[[a,b]] = _hp
          qq[[a,b]] = _hp
        end
      }
    }
    q = qq
  end
  -1
end

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