結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-10-26 14:39:48 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 1,914 bytes |
コンパイル時間 | 39 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-07-05 07:11:31 |
合計ジャッジ時間 | 2,759 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
Main.rb:81: warning: assigned but unused variable - next_x Main.rb:82: warning: assigned but unused variable - next_y Syntax OK
ソースコード
hw = gets.split(" ").map(&:to_i)@h = hw[0]@w = hw[1]sg = gets.split(" ").map(&:to_i)@s = sg[0] - 1 + (sg[1] - 1) * @h#p @ssx = sg[0]sy = sg[1]@s = [sx, sy]@g = sg[2] - 1 + (sg[3] - 1) * @h#p @ggx = sg[2]gy = sg[3]@g = [gx, gy]@maze = []@h.times do@maze << gets.strip.split('').map(&:to_i)#p @mazeend@maze.flatten!#p @mazedef dfs(pos, path)x = pos[0]y = pos[1]#p path[[1, 0], [0, -1], [-1,0], [0, 1]].each do |dir|dx = dir[0]dy = dir[1]next_x = x + dxnext_y = y + dy#print "#{x},#{y} -> #{next_x}, #{next_y}\n"#next_pos = pos + dx + dy * @w#return if next_pos == @g#next if next_pos < 0 || next_pos >= @h * @wnext if next_x < 1 || next_x > @h || next_y < 1 || next_y > @wnext_pos = [next_x, next_y]next if path.include?(next_pos)# next if @maze[next_x - 1 + next_y * @w]#p @maze[(next_x - 1) * @w + next_y - 1]next if (@maze[(next_x - 1) * @w + next_y - 1] - @maze[(x - 1) * @w + y - 1]).abs > 1if @s == [next_x, next_y]puts "YES"exitend#p dir#p next_pospath << next_posdfs(next_pos, path.clone)end[[1, 0], [0, -1], [-1,0], [0, 1]].each do |dir|dx = dir[0]dy = dir[1]next_x = x + 2 * dxnext_y = y + 2 * dy#print "#{x},#{y} -> #{next_x}, #{next_y}\n"next if next_x < 1 || next_x > @h || next_y < 1 || next_y > @wnext_pos = [next_x, next_y]next if path.include?(next_pos)next if @maze[(x + dx - 1) * @w + (y + dy) - 1] >= @maze[(x - 1) * @w + y - 1]next if @maze[(next_x - 1) * @w + next_y - 1] != @maze[(x - 1) * @w + y - 1]if @s == [next_x, next_y]puts "YES"exitend#p dir#p next_pos#print "Bridge #{x}, #{y} -> #{next_x}, #{next_y}\n"path << next_posdfs(next_pos, path.clone)endendnext_x = 2next_y = 5#p @maze[(next_x - 1) * @w + next_y - 1]#exitif @s == @gputs "YES"exitendpath = [@g]dfs(path[0], path.clone)puts "NO"