結果

問題 No.424 立体迷路
ユーザー htkbhtkb
提出日時 2018-05-26 12:11:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 854 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 8,740 KB
最終ジャッジ日時 2023-09-18 17:03:59
合計ジャッジ時間 1,712 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,704 KB
testcase_01 AC 22 ms
8,540 KB
testcase_02 AC 20 ms
8,548 KB
testcase_03 AC 19 ms
8,612 KB
testcase_04 AC 19 ms
8,592 KB
testcase_05 AC 19 ms
8,556 KB
testcase_06 AC 19 ms
8,500 KB
testcase_07 AC 19 ms
8,668 KB
testcase_08 AC 18 ms
8,716 KB
testcase_09 AC 19 ms
8,516 KB
testcase_10 AC 19 ms
8,500 KB
testcase_11 AC 19 ms
8,560 KB
testcase_12 AC 19 ms
8,512 KB
testcase_13 AC 21 ms
8,568 KB
testcase_14 AC 19 ms
8,676 KB
testcase_15 AC 19 ms
8,540 KB
testcase_16 AC 18 ms
8,652 KB
testcase_17 AC 20 ms
8,704 KB
testcase_18 AC 19 ms
8,588 KB
testcase_19 AC 20 ms
8,736 KB
testcase_20 AC 19 ms
8,640 KB
testcase_21 AC 20 ms
8,664 KB
testcase_22 AC 19 ms
8,680 KB
testcase_23 AC 19 ms
8,600 KB
testcase_24 AC 27 ms
8,740 KB
testcase_25 AC 27 ms
8,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
H, W = map(int, input().split())
sy, sx, gy, gx = map(int, input().split())
inf = float("inf")
b = [[inf]+list(map(int, input()))+[inf] for _ in [0]*H]
b = [[inf]*(W+2)] + b + [[inf]*(W+2)]

visited = [[0]*(W+2) for _ in [0]*(H+2)]
visited[sy][sx] = 1
dq = deque([(sx, sy, b[sy][sx])])
popleft, append = dq.popleft, dq.append
while dq:
    x, y, h = popleft()
    if x == gx and y == gy:
        print("YES")
        exit()
    for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0)):
        nx, ny = x+dx, y+dy
        h2 = b[ny][nx]
        if abs(h-h2) <= 1 and visited[ny][nx] == 0:
            visited[ny][nx] = 1
            append((nx, ny, h2))

        if h > h2 and b[ny+dy][nx+dx] == h and visited[ny+dy][nx+dx] == 0:
            visited[ny+dy][nx+dx] = 1
            append((nx+dx, ny+dy, b[ny+dy][nx+dx]))

print("NO")
0