結果

問題 No.424 立体迷路
ユーザー AEnAEn
提出日時 2022-05-16 18:44:37
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 993 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 79,876 KB
最終ジャッジ日時 2023-10-12 12:32:50
合計ジャッジ時間 6,797 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

from sympy import Q

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