結果

問題 No.20 砂漠のオアシス
ユーザー letrangerjpletrangerjp
提出日時 2017-06-03 19:06:30
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-21 07:12:18
合計ジャッジ時間 5,057 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
12,288 KB
testcase_01 AC 84 ms
12,288 KB
testcase_02 AC 87 ms
12,160 KB
testcase_03 AC 104 ms
12,672 KB
testcase_04 AC 130 ms
12,544 KB
testcase_05 AC 393 ms
18,560 KB
testcase_06 AC 139 ms
13,184 KB
testcase_07 AC 721 ms
19,584 KB
testcase_08 AC 239 ms
14,592 KB
testcase_09 AC 568 ms
18,304 KB
testcase_10 WA -
testcase_11 AC 80 ms
12,160 KB
testcase_12 WA -
testcase_13 AC 106 ms
12,416 KB
testcase_14 AC 146 ms
12,800 KB
testcase_15 AC 134 ms
12,800 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 220 ms
13,824 KB
testcase_20 AC 101 ms
12,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, V, X, Y = gets.split.take(4).map(&:to_i)
L = N.times.map{
  gets.split.take(N).map(&:to_i)
}

DIRS = [[1,0], [0,1], [-1, 0], [0,-1]]

$pq = []
$dp = Hash.new(0)
def f(start_x, start_y, start_hp)
  $pq << [start_hp, start_x, start_y, 1]
  $dp[[start_x, start_y, 1]] = start_hp
  while !$pq.empty?
    hp, x, y, oas = $pq.pop
    return true if x == N-1 && y == N-1
    next if $dp[[x,y,oas]] != hp
    if x == X-1 && y == Y-1 && oas == 1
      hp *= 2
      oas = 0
    end
    DIRS.each{|dx, dy|
      _x = x + dx
      _y = y + dy
      next if !_x.between?(0, N-1)
      next if !_y.between?(0, N-1)
      _hp = hp - L[_x][_y]
      next if _hp <= 0
      if $dp[[_x, _y, oas]] < _hp
        # p [_x, _y]
        $dp[[_x, _y, oas]] = _hp
        elem = [_hp, _x, _y, oas]
        $pq[$pq.bsearch_index{|v|(v<=>elem) > 0}||$pq.size,0] = [elem]
        # p $pq
      end
    }
  end
  false
end

puts f(0, 0, V) ? :YES : :NO
0