結果

問題 No.424 立体迷路
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2016-09-22 23:06:08
言語 Ruby
(3.2.2)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 11,368 KB
実行使用メモリ 15,984 KB
最終ジャッジ日時 2023-09-18 16:50:17
合計ジャッジ時間 3,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,152 KB
testcase_01 AC 86 ms
15,128 KB
testcase_02 AC 84 ms
15,108 KB
testcase_03 AC 84 ms
15,180 KB
testcase_04 AC 86 ms
15,136 KB
testcase_05 AC 83 ms
15,060 KB
testcase_06 AC 84 ms
15,140 KB
testcase_07 AC 85 ms
15,296 KB
testcase_08 AC 86 ms
15,108 KB
testcase_09 AC 84 ms
15,180 KB
testcase_10 AC 84 ms
15,040 KB
testcase_11 AC 85 ms
15,148 KB
testcase_12 AC 84 ms
15,340 KB
testcase_13 AC 85 ms
15,152 KB
testcase_14 AC 84 ms
15,064 KB
testcase_15 AC 86 ms
15,072 KB
testcase_16 AC 84 ms
15,120 KB
testcase_17 AC 90 ms
15,388 KB
testcase_18 AC 90 ms
15,440 KB
testcase_19 AC 89 ms
15,380 KB
testcase_20 AC 88 ms
15,304 KB
testcase_21 AC 84 ms
15,204 KB
testcase_22 AC 83 ms
15,136 KB
testcase_23 AC 85 ms
15,304 KB
testcase_24 AC 93 ms
15,740 KB
testcase_25 AC 94 ms
15,984 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !
G = Hash.new{|h,k| h[k] = []}

def dfs(s,t,size)
    used = Array.new(size)
    stack = [s]
    until stack.empty?
        v = stack.pop
        used[v] = true
        if v == t
            break
        end
        
        G[v].reject {|u| used[u] }.each do |u| 
            stack << u
        end
    end
    used[t]
end

h,w = gets.split.map(&:to_i)
sy, sx, gy, gx = gets.split.map(&:to_i).map {|v| v - 1}
map = h.times.map do 
    gets.chomp.chars.map(&:to_i)
end

h.times do |y|
    w.times.each_cons(2) do |a,b|
        if (map[y][a] - map[y][b]).abs <= 1
            G[y * w + a] << y * w + b
            G[y * w + b] << y * w + a
        end
    end
    w.times.each_cons(3) do |a,b,c|
        if map[y][a] == map[y][c] && map[y][a] > map[y][b]
            G[y * w + a] << y * w + c
            G[y * w + c] << y * w + a
        end
    end
end
w.times do |x|
    h.times.each_cons(2) do |a,b|
        if (map[a][x] - map[b][x]).abs <= 1
            G[a * w + x] << b * w + x
            G[b * w + x] << a * w + x
        end
    end
    h.times.each_cons(3) do |a,b,c|
        if map[a][x] == map[c][x] && map[a][x] > map[b][x]
            G[a * w + x] << c * w + x
            G[c * w + x] << a * w + x
        end
    end
end

puts dfs(w * sy + sx, w * gy + gx, h * w) ? "YES" : "NO"
0