結果

問題 No.424 立体迷路
ユーザー AEnAEn
提出日時 2022-05-16 18:45:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 77,840 KB
最終ジャッジ日時 2023-10-12 12:33:05
合計ジャッジ時間 3,931 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,792 KB
testcase_01 AC 92 ms
71,672 KB
testcase_02 AC 92 ms
71,764 KB
testcase_03 AC 91 ms
71,736 KB
testcase_04 AC 93 ms
71,792 KB
testcase_05 AC 92 ms
71,812 KB
testcase_06 AC 92 ms
71,664 KB
testcase_07 AC 90 ms
71,796 KB
testcase_08 AC 90 ms
71,648 KB
testcase_09 AC 92 ms
71,492 KB
testcase_10 AC 89 ms
71,496 KB
testcase_11 AC 90 ms
71,656 KB
testcase_12 AC 91 ms
71,300 KB
testcase_13 AC 91 ms
71,652 KB
testcase_14 AC 89 ms
71,588 KB
testcase_15 AC 89 ms
71,904 KB
testcase_16 AC 92 ms
71,668 KB
testcase_17 AC 92 ms
71,548 KB
testcase_18 AC 89 ms
71,616 KB
testcase_19 AC 93 ms
71,352 KB
testcase_20 AC 91 ms
71,584 KB
testcase_21 AC 92 ms
71,548 KB
testcase_22 AC 91 ms
71,664 KB
testcase_23 AC 91 ms
71,792 KB
testcase_24 AC 121 ms
77,760 KB
testcase_25 AC 124 ms
77,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H, W = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
m = []
for i in range(H):
    m.append(input())

q = deque()
dis = [[-1]*W for _ in range(H)]
dis[sx-1][sy-1] = 0
q.append((sx-1, sy-1))
xx = [1, 0, -1, 0]
pp = [2, 0, -2, 0]
yy = [0, 1, 0, -1]
qq = [0, 2, 0, -2]

while q:
    x, y = q.popleft()
    for px, py in zip(xx, yy):
        cx = x+px
        cy = y+py
        if 0<=cx<H and 0<=cy<W and dis[cx][cy] == -1:
            if abs(int(m[x][y])-int(m[cx][cy])) <= 1:
                dis[cx][cy] = dis[x][y] + 1
                q.append((cx, cy))
    for px, py in zip(pp, qq):
        cx = x+px
        cy = y+py
        if 0<=cx<H and 0<=cy<W and dis[cx][cy] == -1:
            if int(m[cx][cy]) == int(m[x][y]) and int(m[(cx+x)//2][(cy+y)//2]) < int(m[x][y]):
                dis[cx][cy] = dis[x][y]+1
                q.append((cx, cy))
if dis[gx-1][gy-1] == -1:
    print('NO')
else:
    print('YES')        
0