結果
問題 | No.424 立体迷路 |
ユーザー | suppy193 |
提出日時 | 2016-10-26 14:39:48 |
言語 | Ruby (3.3.0) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
12,160 KB |
testcase_01 | AC | 75 ms
12,288 KB |
testcase_02 | AC | 72 ms
12,288 KB |
testcase_03 | AC | 72 ms
12,160 KB |
testcase_04 | AC | 72 ms
12,288 KB |
testcase_05 | AC | 70 ms
12,160 KB |
testcase_06 | AC | 72 ms
12,160 KB |
testcase_07 | AC | 71 ms
12,160 KB |
testcase_08 | AC | 72 ms
12,288 KB |
testcase_09 | AC | 71 ms
12,160 KB |
testcase_10 | AC | 71 ms
12,160 KB |
testcase_11 | AC | 71 ms
12,160 KB |
testcase_12 | AC | 71 ms
12,160 KB |
testcase_13 | AC | 70 ms
12,032 KB |
testcase_14 | AC | 72 ms
12,160 KB |
testcase_15 | AC | 71 ms
12,288 KB |
testcase_16 | AC | 72 ms
12,160 KB |
testcase_17 | AC | 73 ms
12,288 KB |
testcase_18 | AC | 74 ms
12,416 KB |
testcase_19 | AC | 73 ms
12,288 KB |
testcase_20 | AC | 73 ms
12,288 KB |
testcase_21 | AC | 71 ms
12,160 KB |
testcase_22 | AC | 76 ms
12,032 KB |
testcase_23 | AC | 71 ms
12,160 KB |
testcase_24 | AC | 77 ms
12,416 KB |
testcase_25 | AC | 77 ms
12,160 KB |
コンパイルメッセージ
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 @s sx = sg[0] sy = sg[1] @s = [sx, sy] @g = sg[2] - 1 + (sg[3] - 1) * @h #p @g gx = sg[2] gy = sg[3] @g = [gx, gy] @maze = [] @h.times do @maze << gets.strip.split('').map(&:to_i) #p @maze end @maze.flatten! #p @maze def 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 + dx next_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 * @w next if next_x < 1 || next_x > @h || next_y < 1 || next_y > @w next_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 > 1 if @s == [next_x, next_y] puts "YES" exit end #p dir #p next_pos path << next_pos dfs(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 * dx next_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 > @w next_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" exit end #p dir #p next_pos #print "Bridge #{x}, #{y} -> #{next_x}, #{next_y}\n" path << next_pos dfs(next_pos, path.clone) end end next_x = 2 next_y = 5 #p @maze[(next_x - 1) * @w + next_y - 1] #exit if @s == @g puts "YES" exit end path = [@g] dfs(path[0], path.clone) puts "NO"