結果

問題 No.34 砂漠の行商人
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2015-06-15 21:29:05
言語 Ruby
(3.3.0)
結果
AC  
実行時間 496 ms / 5,000 ms
コード長 1,305 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 11,416 KB
実行使用メモリ 17,788 KB
最終ジャッジ日時 2023-09-10 19:09:22
合計ジャッジ時間 6,748 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,116 KB
testcase_01 AC 83 ms
15,072 KB
testcase_02 AC 90 ms
15,092 KB
testcase_03 AC 85 ms
15,084 KB
testcase_04 AC 136 ms
15,640 KB
testcase_05 AC 153 ms
15,976 KB
testcase_06 AC 124 ms
15,684 KB
testcase_07 AC 251 ms
16,216 KB
testcase_08 AC 278 ms
16,640 KB
testcase_09 AC 222 ms
16,492 KB
testcase_10 AC 138 ms
16,588 KB
testcase_11 AC 184 ms
16,940 KB
testcase_12 AC 106 ms
15,656 KB
testcase_13 AC 496 ms
17,772 KB
testcase_14 AC 495 ms
17,788 KB
testcase_15 AC 91 ms
15,616 KB
testcase_16 AC 128 ms
15,896 KB
testcase_17 AC 92 ms
15,800 KB
testcase_18 AC 92 ms
15,044 KB
testcase_19 AC 248 ms
16,928 KB
testcase_20 AC 347 ms
17,112 KB
testcase_21 AC 104 ms
16,268 KB
testcase_22 AC 104 ms
16,192 KB
testcase_23 AC 91 ms
15,564 KB
testcase_24 AC 394 ms
17,252 KB
testcase_25 AC 126 ms
15,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Point
  attr_reader :x, :y

  def initialize(x, y)
    @x = x
    @y = y
  end

  def in?(n)
    0 < @x && @x <= n && 0 < @y && @y <= n
  end

  def left
    Point.new(@x + 1, @y)
  end

  def right
    Point.new(@x - 1, @y)
  end

  def up
    Point.new(@x, @y + 1)
  end

  def down
    Point.new(@x, @y - 1)
  end

  def eql?(other)
    @x == other.x && @y == other.y
  end

  def ==(other)
    eql?(other)
  end

  def hash
    @x + @y * 100
  end
end

n, v, sx, sy, gx, gy = gets.split.map(&:to_i)
map = Hash.new(0)
vmap = Hash.new(-1)
(1..n).each do |y|
  gets.split.map(&:to_i).each.with_index(1) do |l, x|
    map[Point.new(x, y)] = l
  end
end

s = Point.new(sx, sy)
g = Point.new(gx, gy)

count = 0
list = {}
list[s] = v
vmap[s] = v
loop do
  count += 1
  next_list = {}
  list.each do |point, life|
    [point.left, point.right, point.up, point.down].each do |next_point|
      if next_point.in?(n)
        next_life = life - map[next_point]
        if next_life > 0
          if next_point == g
            puts count
            exit
          elsif next_life > vmap[next_point]
            vmap[next_point] = next_life
            next_list[next_point] = next_life
          end
        end
      end
    end
  end
  if next_list.empty?
    break
  end
  list = next_list
end
puts(-1)
0