結果

問題 No.424 立体迷路
ユーザー titiatitia
提出日時 2023-03-29 01:27:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,056 KB
実行使用メモリ 10,304 KB
最終ジャッジ日時 2023-10-20 17:48:38
合計ジャッジ時間 1,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,276 KB
testcase_01 AC 27 ms
10,276 KB
testcase_02 AC 27 ms
10,276 KB
testcase_03 AC 30 ms
10,276 KB
testcase_04 AC 29 ms
10,280 KB
testcase_05 AC 29 ms
10,276 KB
testcase_06 AC 29 ms
10,276 KB
testcase_07 AC 26 ms
10,276 KB
testcase_08 AC 26 ms
10,276 KB
testcase_09 AC 27 ms
10,276 KB
testcase_10 AC 28 ms
10,276 KB
testcase_11 AC 26 ms
10,276 KB
testcase_12 AC 27 ms
10,276 KB
testcase_13 AC 29 ms
10,280 KB
testcase_14 AC 28 ms
10,280 KB
testcase_15 AC 30 ms
10,280 KB
testcase_16 AC 27 ms
10,280 KB
testcase_17 AC 28 ms
10,304 KB
testcase_18 AC 28 ms
10,304 KB
testcase_19 AC 27 ms
10,304 KB
testcase_20 AC 27 ms
10,304 KB
testcase_21 AC 26 ms
10,276 KB
testcase_22 AC 27 ms
10,280 KB
testcase_23 AC 28 ms
10,276 KB
testcase_24 AC 34 ms
10,304 KB
testcase_25 AC 36 ms
10,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

MAP=[list(map(int,list(input().strip()))) for i in range(H)]
USE=[[0]*W for i in range(H)]
USE[sx-1][sy-1]=1
Q=deque([(sx-1,sy-1)])

while Q:
    x,y=Q.popleft()

    for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
        if 0<=z<H and 0<=w<W and USE[z][w]==0:
            if abs(MAP[x][y]-MAP[z][w])<=1:
                USE[z][w]=1
                Q.append((z,w))

    if x-2>=0:
        if USE[x-2][y]==0 and MAP[x-2][y]==MAP[x][y] and MAP[x-1][y]<MAP[x][y]:
            USE[x-2][y]=1
            Q.append((x-2,y))
    if y-2>=0:
        if USE[x][y-2]==0 and MAP[x][y-2]==MAP[x][y] and MAP[x][y-1]<MAP[x][y]:
            USE[x][y-2]=1
            Q.append((x,y-2))
    if x+2<H:
        if USE[x+2][y]==0 and MAP[x+2][y]==MAP[x][y] and MAP[x+1][y]<MAP[x][y]:
            USE[x+2][y]=1
            Q.append((x+2,y))
    if y+2<W:
        if USE[x][y+2]==0 and MAP[x][y+2]==MAP[x][y] and MAP[x][y+1]<MAP[x][y]:
            USE[x][y+2]=1
            Q.append((x,y+2))

if USE[gx-1][gy-1]==1:
    print("YES")
else:
    print("NO")
0