結果

問題 No.424 立体迷路
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-21 15:14:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,800 KB
最終ジャッジ日時 2023-08-16 20:39:28
合計ジャッジ時間 1,730 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,740 KB
testcase_01 AC 18 ms
8,696 KB
testcase_02 AC 16 ms
8,696 KB
testcase_03 AC 15 ms
8,592 KB
testcase_04 AC 18 ms
8,596 KB
testcase_05 AC 16 ms
8,648 KB
testcase_06 AC 16 ms
8,600 KB
testcase_07 AC 16 ms
8,560 KB
testcase_08 AC 16 ms
8,696 KB
testcase_09 AC 16 ms
8,588 KB
testcase_10 AC 17 ms
8,548 KB
testcase_11 AC 16 ms
8,700 KB
testcase_12 AC 16 ms
8,592 KB
testcase_13 AC 17 ms
8,648 KB
testcase_14 AC 16 ms
8,724 KB
testcase_15 AC 17 ms
8,652 KB
testcase_16 AC 17 ms
8,640 KB
testcase_17 AC 16 ms
8,800 KB
testcase_18 AC 16 ms
8,652 KB
testcase_19 AC 15 ms
8,616 KB
testcase_20 AC 15 ms
8,776 KB
testcase_21 AC 16 ms
8,644 KB
testcase_22 AC 17 ms
8,560 KB
testcase_23 AC 16 ms
8,576 KB
testcase_24 AC 46 ms
8,720 KB
testcase_25 AC 46 ms
8,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
h,w=map(int,input().split())
sy,sx,gy,gx=map(int,input().split())
sy-=1;sx-=1;gy-=1;gx-=1
g=[list(input()) for _ in range(h)]
visit=[[False]*w for _ in range(h)]
q=deque()
q.append((sy,sx))
while q:
    y,x=q.popleft()
    if visit[y][x]:
        continue
    visit[y][x]=True
    dy=[-1,0,1,0]
    dx=[0,-1,0,1]
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        if not (0<=ny<h and 0<=nx<w):
            continue
        if abs(int(g[ny][nx])-int(g[y][x]))>1:
            continue
        if visit[ny][nx]:
            continue
        q.append((ny,nx))
    dy2=[-2,0,2,0]
    dx2=[0,-2,0,2]
    for i in range(4):
        ny2=y+dy2[i]
        nx2=x+dx2[i]
        if not (0<=ny2<h and 0<=nx2<w):
            continue
        if int(g[ny2][nx2])!=int(g[y][x]):
            continue
        if int(g[(ny2+y)//2][(nx2+x)//2])>int(g[y][x]):
            continue
        q.append((ny2,nx2))
print('YES' if visit[gy][gx] else 'NO')
0