結果

問題 No.424 立体迷路
ユーザー ayaoniayaoni
提出日時 2020-12-18 05:32:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,857 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 66,496 KB
最終ジャッジ日時 2023-10-21 07:52:22
合計ジャッジ時間 2,648 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,480 KB
testcase_01 AC 44 ms
55,480 KB
testcase_02 AC 44 ms
55,480 KB
testcase_03 AC 43 ms
55,480 KB
testcase_04 AC 45 ms
55,480 KB
testcase_05 AC 44 ms
55,480 KB
testcase_06 AC 43 ms
55,480 KB
testcase_07 AC 44 ms
55,480 KB
testcase_08 AC 44 ms
55,480 KB
testcase_09 AC 43 ms
55,480 KB
testcase_10 AC 44 ms
55,480 KB
testcase_11 AC 44 ms
55,480 KB
testcase_12 AC 43 ms
55,480 KB
testcase_13 AC 45 ms
55,480 KB
testcase_14 AC 47 ms
55,480 KB
testcase_15 AC 44 ms
55,480 KB
testcase_16 AC 44 ms
55,480 KB
testcase_17 AC 49 ms
61,480 KB
testcase_18 AC 48 ms
61,480 KB
testcase_19 AC 47 ms
61,480 KB
testcase_20 AC 47 ms
61,480 KB
testcase_21 AC 44 ms
55,480 KB
testcase_22 AC 44 ms
55,480 KB
testcase_23 AC 43 ms
55,480 KB
testcase_24 AC 60 ms
66,492 KB
testcase_25 AC 61 ms
66,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


H,W = MI()
sx,sy,gx,gy = MI()
B = [[0]*(W+1)]+[[0]+LI2() for _ in range(H)]

flag = [[0]*(W+1) for _ in range(H+1)]
flag[sx][sy] = 1
deq = deque([(sx,sy)])
while deq:
    x,y = deq.pop()
    if 1 <= x-1 <= H and flag[x-1][y] == 0 and abs(B[x-1][y]-B[x][y]) <= 1:
        flag[x-1][y] = 1
        deq.appendleft((x-1,y))
    if 1 <= x+1 <= H and flag[x+1][y] == 0 and abs(B[x+1][y]-B[x][y]) <= 1:
        flag[x+1][y] = 1
        deq.appendleft((x+1,y))
    if 1 <= y-1 <= W and flag[x][y-1] == 0 and abs(B[x][y-1]-B[x][y]) <= 1:
        flag[x][y-1] = 1
        deq.appendleft((x,y-1))
    if 1 <= y+1 <= W and flag[x][y+1] == 0 and abs(B[x][y+1]-B[x][y]) <= 1:
        flag[x][y+1] = 1
        deq.appendleft((x,y+1))
    if 1 <= x-2 <= H and flag[x-2][y] == 0 and B[x-2][y] == B[x][y] and B[x-1][y] < B[x][y]:
        flag[x-2][y] = 1
        deq.appendleft((x-2,y))
    if 1 <= x+2 <= H and flag[x+2][y] == 0 and B[x+2][y] == B[x][y] and B[x+1][y] < B[x][y]:
        flag[x+2][y] = 1
        deq.appendleft((x+2,y))
    if 1 <= y-2 <= W and flag[x][y-2] == 0 and B[x][y-2] == B[x][y] and B[x][y-1] < B[x][y]:
        flag[x][y-2] = 1
        deq.appendleft((x,y-2))
    if 1 <= y+2 <= W and flag[x][y+2] == 0 and B[x][y+2] == B[x][y] and B[x][y+1] < B[x][y]:
        flag[x][y+2] = 1
        deq.appendleft((x,y+2))

if flag[gx][gy]:
    print('YES')
else:
    print('NO')
0