結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
urutom
|
| 提出日時 | 2017-04-17 17:20:14 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 668 bytes |
| コンパイル時間 | 146 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-07-19 05:30:59 |
| 合計ジャッジ時間 | 3,374 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 WA * 2 |
コンパイルメッセージ
Syntax OK
ソースコード
h,w=gets.split.map(&:to_i)
sx,sy,gx,gy=gets.split.map{|s|s.to_i-1}
maze=h.times.map{gets.chomp.bytes.to_a}
init_state=[sx,sy]
q=[init_state]
visited={}
until q.empty?
curr_state=q.shift
next if visited[curr_state]
visited[curr_state]=true
if curr_state==[gx,gy]
puts "YES"
exit
end
height=maze.dig(*curr_state)
x,y=curr_state
[
[[[1,0],[0,1],[-1,0],[0,-1]],1],
[[[2,0],[0,2],[-2,0],[0,-2]],0]
].each{|directions,threshold|
directions.each{|dx,dy|
nx,ny=x+dx,y+dy
next unless (0...h)===nx
next unless (0...w)===ny
next_state=[nx,ny]
next unless (maze.dig(*next_state)-height).abs<=threshold
q.push next_state
}
}
end
puts "NO"
urutom