結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2017-04-17 17:27:16 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 824 bytes |
コンパイル時間 | 117 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-07-05 07:14:13 |
合計ジャッジ時間 | 2,681 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
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.shiftnext if visited[curr_state]visited[curr_state]=trueif curr_state==[gx,gy]puts "YES"exitendheight=maze.dig(*curr_state)x,y=curr_state[[1,0],[0,1],[-1,0],[0,-1]].each{|dx,dy|nx,ny=x+dx,y+dynext unless (0...h)===nxnext unless (0...w)===nynext_state=[nx,ny]next if (maze.dig(*next_state)-height).abs>1q.push next_state}[[2,0],[0,2],[-2,0],[0,-2]].each{|dx,dy|nx,ny=x+dx,y+dynext unless (0...h)===nxnext unless (0...w)===nynext_state=[nx,ny]next unless maze.dig(*next_state)==heightmiddle=[x+dx/2,y+dy/2]next if maze.dig(*middle)>=heightq.push next_state}endputs "NO"