結果

問題 No.424 立体迷路
ユーザー H3PO4H3PO4
提出日時 2020-07-30 14:44:53
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 8,912 KB
最終ジャッジ日時 2023-09-17 03:22:51
合計ジャッジ時間 1,678 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,612 KB
testcase_01 AC 19 ms
8,544 KB
testcase_02 AC 18 ms
8,680 KB
testcase_03 AC 19 ms
8,668 KB
testcase_04 AC 21 ms
8,728 KB
testcase_05 AC 19 ms
8,684 KB
testcase_06 AC 19 ms
8,680 KB
testcase_07 AC 19 ms
8,672 KB
testcase_08 AC 19 ms
8,680 KB
testcase_09 AC 19 ms
8,580 KB
testcase_10 AC 18 ms
8,736 KB
testcase_11 AC 18 ms
8,680 KB
testcase_12 AC 19 ms
8,708 KB
testcase_13 AC 18 ms
8,672 KB
testcase_14 AC 19 ms
8,544 KB
testcase_15 AC 19 ms
8,580 KB
testcase_16 AC 19 ms
8,544 KB
testcase_17 AC 19 ms
8,764 KB
testcase_18 AC 19 ms
8,632 KB
testcase_19 AC 19 ms
8,756 KB
testcase_20 AC 19 ms
8,568 KB
testcase_21 AC 18 ms
8,612 KB
testcase_22 AC 19 ms
8,732 KB
testcase_23 AC 18 ms
8,680 KB
testcase_24 AC 34 ms
8,732 KB
testcase_25 AC 34 ms
8,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

int1 = lambda x: int(x) - 1

H, W = map(int, input().split())
Sx, Sy, Gx, Gy = map(int1, input().split())
B = [[int(x) for x in input()] for _ in range(H)]

# bfs
d = deque([(Sx, Sy)])
visited = set(d)
while d:
    x, y = d.popleft()
    for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
        if 0 <= x + dx < H and 0 <= y + dy < W and (x + dx, y + dy) not in visited:
            if abs(B[x + dx][y + dy] - B[x][y]) <= 1:
                d.append(((x + dx, y + dy)))
                visited.add((x + dx, y + dy))
    for dx, dy in ((0, 2), (2, 0), (0, -2), (-2, 0)):
        if 0 <= x + dx < H and 0 <= y + dy < W and (x + dx, y + dy) not in visited:
            if B[x + dx][y + dy] == B[x][y] > B[x + dx // 2][y + dy // 2]:
                d.append(((x + dx, y + dy)))
                visited.add((x + dx, y + dy))

print('YES' if (Gx, Gy) in visited else 'NO')
0