結果
問題 | No.20 砂漠のオアシス |
ユーザー | letrangerjp |
提出日時 | 2017-06-03 19:23:53 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 711 ms / 5,000 ms |
コード長 | 1,075 bytes |
コンパイル時間 | 679 ms |
コンパイル使用メモリ | 11,140 KB |
実行使用メモリ | 21,320 KB |
最終ジャッジ日時 | 2023-08-03 08:22:34 |
合計ジャッジ時間 | 5,602 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 83 ms
15,292 KB |
testcase_01 | AC | 83 ms
15,152 KB |
testcase_02 | AC | 84 ms
15,280 KB |
testcase_03 | AC | 104 ms
15,576 KB |
testcase_04 | AC | 124 ms
15,704 KB |
testcase_05 | AC | 442 ms
20,668 KB |
testcase_06 | AC | 143 ms
16,268 KB |
testcase_07 | AC | 711 ms
21,320 KB |
testcase_08 | AC | 235 ms
17,148 KB |
testcase_09 | AC | 638 ms
21,188 KB |
testcase_10 | AC | 82 ms
15,224 KB |
testcase_11 | AC | 83 ms
15,292 KB |
testcase_12 | AC | 107 ms
15,460 KB |
testcase_13 | AC | 106 ms
15,500 KB |
testcase_14 | AC | 135 ms
15,980 KB |
testcase_15 | AC | 124 ms
15,472 KB |
testcase_16 | AC | 216 ms
16,752 KB |
testcase_17 | AC | 174 ms
16,260 KB |
testcase_18 | AC | 188 ms
16,500 KB |
testcase_19 | AC | 213 ms
16,692 KB |
testcase_20 | AC | 93 ms
15,280 KB |
コンパイルメッセージ
Syntax OK
ソースコード
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 if x == N-1 && y == N-1 return true end # p 1 if $dp[[x,y,oas]] != hp # 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[_y][_x] # if _x == X-1 && _y == Y-1 # p [_x, _y] # p L[_x][_y] # p _hp # end 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 end puts f(0, 0, V) ? :YES : :NO