結果

問題 No.424 立体迷路
ユーザー mlihua09mlihua09
提出日時 2020-09-12 13:07:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,530 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 77,736 KB
最終ジャッジ日時 2023-08-30 07:08:35
合計ジャッジ時間 4,355 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,448 KB
testcase_01 AC 91 ms
71,848 KB
testcase_02 AC 92 ms
71,560 KB
testcase_03 AC 92 ms
71,660 KB
testcase_04 AC 91 ms
71,608 KB
testcase_05 AC 90 ms
71,404 KB
testcase_06 AC 91 ms
71,508 KB
testcase_07 AC 91 ms
71,780 KB
testcase_08 AC 91 ms
71,632 KB
testcase_09 AC 91 ms
71,628 KB
testcase_10 AC 91 ms
71,668 KB
testcase_11 AC 92 ms
71,540 KB
testcase_12 AC 89 ms
71,560 KB
testcase_13 AC 91 ms
71,732 KB
testcase_14 AC 92 ms
71,704 KB
testcase_15 AC 94 ms
71,724 KB
testcase_16 AC 91 ms
71,404 KB
testcase_17 AC 95 ms
77,016 KB
testcase_18 AC 97 ms
77,008 KB
testcase_19 AC 99 ms
76,864 KB
testcase_20 AC 96 ms
76,888 KB
testcase_21 AC 90 ms
71,808 KB
testcase_22 AC 93 ms
71,704 KB
testcase_23 AC 92 ms
71,740 KB
testcase_24 AC 107 ms
77,516 KB
testcase_25 AC 107 ms
77,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


h, w = map(int, input().split())

sx, sy, gx, gy = map(int, input().split())

B = [[int(i) for i in input()] for i in range(h)]

visited = [[0] * w + [1, 1] for i in range(h)] + [[1] * (w + 2)] * 2

from collections import deque
que = deque([sx - 1, sy - 1])
visited[sx - 1][sy - 1] = 1

while que:
    q1, q2 = que.popleft(), que.popleft()
    h = B[q1][q2]
    
    if visited[q1 + 1][q2] == 0 and abs(B[q1 + 1][q2] - h) < 2:
        visited[q1 + 1][q2] = 1
        que.extend([q1 + 1, q2])
    if visited[q1 - 1][q2] == 0 and abs(B[q1 - 1][q2] - h) < 2:
        visited[q1 - 1][q2] = 1
        que.extend([q1 - 1, q2])
    if visited[q1][q2 + 1] == 0 and abs(B[q1][q2 + 1] - h) < 2:
        visited[q1][q2 + 1] = 1
        que.extend([q1, q2 + 1])
    if visited[q1][q2 - 1] == 0 and abs(B[q1][q2 - 1] - h) < 2:
        visited[q1][q2 - 1] = 1
        que.extend([q1, q2 - 1])
    if visited[q1 + 2][q2] == 0 and B[q1 + 2][q2] == h and B[q1 + 1][q2] < h:
        visited[q1 + 2][q2] = 1
        que.extend([q1 + 2, q2])
    if visited[q1 - 2][q2] == 0 and B[q1 - 2][q2] == h and B[q1 - 1][q2] < h:
        visited[q1 - 2][q2] = 1
        que.extend([q1 - 2, q2])
    if visited[q1][q2 + 2] == 0 and B[q1][q2 + 2] == h and B[q1][q2 + 1] < h:
        visited[q1][q2 + 2] = 1
        que.extend([q1, q2 + 2])
    if visited[q1][q2 - 2] == 0 and B[q1][q2 - 2] == h and B[q1][q2 - 1] < h:
        visited[q1][q2 - 2] = 1
        que.extend([q1, q2 - 2])

if visited[gx - 1][gy - 1]:
    print('YES')
else:
    print('NO')
        
0