結果

問題 No.34 砂漠の行商人
ユーザー letrangerjpletrangerjp
提出日時 2017-06-13 21:38:52
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,012 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 16,844 KB
最終ジャッジ日時 2023-10-24 21:51:04
合計ジャッジ時間 4,857 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
16,084 KB
testcase_01 AC 78 ms
16,084 KB
testcase_02 AC 86 ms
16,340 KB
testcase_03 AC 78 ms
16,084 KB
testcase_04 WA -
testcase_05 AC 284 ms
16,620 KB
testcase_06 AC 102 ms
16,408 KB
testcase_07 AC 450 ms
16,756 KB
testcase_08 AC 677 ms
16,844 KB
testcase_09 AC 82 ms
16,300 KB
testcase_10 AC 81 ms
16,412 KB
testcase_11 AC 82 ms
16,412 KB
testcase_12 WA -
testcase_13 AC 82 ms
16,412 KB
testcase_14 AC 81 ms
16,344 KB
testcase_15 AC 79 ms
16,216 KB
testcase_16 AC 79 ms
16,216 KB
testcase_17 AC 81 ms
16,296 KB
testcase_18 AC 80 ms
16,084 KB
testcase_19 AC 96 ms
16,724 KB
testcase_20 AC 81 ms
16,476 KB
testcase_21 AC 85 ms
16,424 KB
testcase_22 AC 83 ms
16,332 KB
testcase_23 AC 81 ms
16,224 KB
testcase_24 AC 82 ms
16,340 KB
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) }
MAX_DMG = MAP.map{|y|y.max}.max

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
    else
      # マンハッタン距離 * 最大ダメージ < hp の枝刈り
      ml = (last[0] - x).abs + (last[1] - y).abs
      if hp > ml * MAX_DMG
        res = step + ml
        break
      end
    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