結果

問題 No.424 立体迷路
ユーザー lloyzlloyz
提出日時 2023-01-12 00:01:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,077 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 77,880 KB
最終ジャッジ日時 2023-08-24 04:25:36
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,528 KB
testcase_01 AC 91 ms
71,624 KB
testcase_02 AC 93 ms
71,716 KB
testcase_03 AC 93 ms
71,328 KB
testcase_04 AC 92 ms
71,716 KB
testcase_05 AC 91 ms
71,484 KB
testcase_06 AC 90 ms
71,476 KB
testcase_07 AC 92 ms
71,712 KB
testcase_08 AC 93 ms
71,620 KB
testcase_09 AC 96 ms
71,680 KB
testcase_10 AC 95 ms
71,480 KB
testcase_11 AC 92 ms
71,652 KB
testcase_12 AC 92 ms
71,464 KB
testcase_13 AC 93 ms
71,712 KB
testcase_14 AC 92 ms
71,704 KB
testcase_15 AC 94 ms
71,528 KB
testcase_16 AC 93 ms
71,576 KB
testcase_17 AC 97 ms
76,848 KB
testcase_18 AC 96 ms
77,268 KB
testcase_19 AC 98 ms
76,920 KB
testcase_20 AC 97 ms
77,204 KB
testcase_21 AC 92 ms
71,628 KB
testcase_22 AC 91 ms
71,788 KB
testcase_23 AC 92 ms
71,320 KB
testcase_24 AC 120 ms
77,880 KB
testcase_25 AC 118 ms
77,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

D = [(1, 0), (0, 1), (-1, 0), (0, -1)]
DD = [(2, 0), (0, 2), (-2, 0), (0, -2)]

h, w = map(int, input().split())
si, sj, gi, gj = map(int, input().split())
si -= 1
sj -= 1
gi -= 1
gj -= 1
B = [list(map(int, list(input()))) for _ in range(h)]

visited = [[False for _ in range(w)] for _ in range(h)]
visited[si][sj] = True
Que = deque([(si, sj)])
while Que:
    ci, cj = Que.popleft()
    if ci == gi and cj == gj:
        print("YES")
        exit()
    for di, dj in D:
        ni = ci + di
        nj = cj + dj
        if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:
            if abs(B[ci][cj] - B[ni][nj]) <= 1:
                visited[ni][nj] = True
                Que.append((ni, nj))
    for di, dj in DD:
        ni = ci + di
        nj = cj + dj
        if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj]:
            mi = (ci + ni) // 2
            mj = (cj + nj) // 2
            if B[ci][cj] == B[ni][nj] and B[ci][cj] > B[mi][mj]:
                visited[ni][nj] = True
                Que.append((ni, nj))
print("NO")
0