結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

$visited = N.times.map{[false] * N}
$oasis = false
DIRS = [[1,0], [0,1], [-1, 0], [0,-1]]
def f(x, y, hp)
  # p [x,y,hp]
  hp -= L[x][y]
  return false if hp <= 0
  return true if x == N-1 && y == N-1
  if x == X && y == Y && !$oasis
    hp *= 2
    $oasis = true
    $visited = N.times.map{[false] * N}
    $visited[x][y] = true
  end
  DIRS.each{|(px, py)|
    _x = x+px
    _y = y+py
    next if !_x.between?(0, N-1)
    next if !_y.between?(0, N-1)
    next if $visited[_x][_y]
    $visited[_x][_y] = true
    return true if f(_x, _y, hp)
    $visited[_x][_y] = false
  }
  false
end

p f(0, 0, V)
0