結果

問題 No.424 立体迷路
コンテスト
ユーザー nebukuro09
提出日時 2016-09-22 22:45:12
言語 PyPy2
(7.3.20)
コンパイル:
pypy2 -m py_compile _filename_
実行:
/usr/bin/pypy2 Main.pyc
結果
AC  
実行時間 67 ms / 2,000 ms
+ 63µs
コード長 1,106 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 59 ms
コンパイル使用メモリ 80,800 KB
実行使用メモリ 83,104 KB
最終ジャッジ日時 2026-07-18 08:33:52
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

H, W = map(int, raw_input().split())
sx, sy, gx, gy = map(int, raw_input().split())
goal = (gx-1, gy-1)
board = [map(int, list(raw_input())) for _ in xrange(H)]

dh = [1, -1, 0, 0]
dw = [0, 0, 1, -1]
stack = [(sx-1, sy-1)]
visited = set()
while len(stack) > 0:
    node = stack.pop()
    if node == goal:
        print 'YES'
        exit()
    if node in visited:
        continue
    visited.add(node)
    for i in xrange(4):
        nh, nw = node[0]+dh[i], node[1]+dw[i]
        if nh < 0 or nh >= H or nw < 0 or nw >= W:
            continue
        if (nh, nw) in visited:
            continue
        if abs(board[nh][nw] - board[node[0]][node[1]]) > 1:
            continue
        stack.append((nh, nw))
    for i in xrange(4):
        nh, nw = node[0]+dh[i]*2, node[1]+dw[i]*2
        if nh < 0 or nh >= H or nw < 0 or nw >= W:
            continue
        if (nh, nw) in visited:
            continue
        a, b, c = board[node[0]][node[1]], board[nh][nw], board[node[0]+dh[i]][node[1]+dw[i]]
        if a != b or c >= a or c >= b:
            continue
        stack.append((nh, nw))
print 'NO'
0