結果

問題 No.424 立体迷路
ユーザー masashi0217masashi0217
提出日時 2021-03-22 04:30:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 11,584 KB
実行使用メモリ 15,452 KB
最終ジャッジ日時 2023-08-14 23:37:44
合計ジャッジ時間 4,054 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,360 KB
testcase_01 AC 86 ms
15,100 KB
testcase_02 AC 86 ms
15,148 KB
testcase_03 AC 85 ms
15,028 KB
testcase_04 AC 85 ms
15,096 KB
testcase_05 AC 85 ms
15,152 KB
testcase_06 AC 84 ms
15,128 KB
testcase_07 AC 86 ms
15,128 KB
testcase_08 AC 85 ms
15,176 KB
testcase_09 AC 87 ms
15,120 KB
testcase_10 AC 88 ms
15,184 KB
testcase_11 AC 84 ms
15,264 KB
testcase_12 AC 84 ms
15,096 KB
testcase_13 AC 86 ms
15,368 KB
testcase_14 AC 84 ms
15,152 KB
testcase_15 AC 84 ms
15,364 KB
testcase_16 AC 83 ms
15,156 KB
testcase_17 AC 86 ms
15,216 KB
testcase_18 AC 88 ms
15,248 KB
testcase_19 AC 85 ms
15,244 KB
testcase_20 AC 86 ms
15,324 KB
testcase_21 AC 83 ms
15,220 KB
testcase_22 AC 83 ms
15,244 KB
testcase_23 AC 84 ms
15,368 KB
testcase_24 AC 89 ms
15,292 KB
testcase_25 AC 91 ms
15,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h, w = gets.chomp.split(" ").map(&:to_i)
sy, sx, gy, gx = gets.chomp.split(" ").map(&:to_i)
one = [[0,1],[0,-1],[1,0],[-1,0],[0,2],[2,0],[-2,0],[0,-2]]
maze = []
h.times do |i|
    b = gets.chomp.split("").map(&:to_i)
    maze << b
end
st = [[sy-1,sx-1]]
arr = Array.new(h).map{Array.new(w,-1)}
arr[sy-1][sx-1] = 0
ok = false
until st == []
    i,j = st.pop
    one.each do |y,x|
        yy = i + y
        xx = j + x
        next if (i+y < 0 || i+y > h-1) || (j+x < 0 || j+x > w-1)
        next if arr[yy][xx] != -1
        if y.abs == 2 || x.abs == 2
            if maze[yy][xx] == maze[i][j]
                if y.abs == 2
                    yyy = i + (y/2)
                    if maze[yy][xx] > maze[yyy][xx]
                        arr[yy][xx] += 1
                        st << [yy,xx]
                    end
                else
                    xxx = j + (x/2)
                    if maze[yy][xx] > maze[yy][xxx]
                        arr[yy][xx] += 1
                        st << [yy,xx]
                    end
                end
            end
        else
            if (maze[yy][xx] - maze[i][j]).abs <= 1
                arr[yy][xx] += 1
                st << [yy,xx]
            end
        end
    end
    if arr[gy-1][gx-1] == 0
        ok = true
        break
    end
    # p st
end
if ok
    puts "YES"
else
    puts "NO"
end
0