結果

問題 No.424 立体迷路
ユーザー H3PO4H3PO4
提出日時 2020-07-30 14:42:58
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 8,860 KB
最終ジャッジ日時 2023-09-17 03:20:08
合計ジャッジ時間 1,380 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,676 KB
testcase_01 AC 16 ms
8,696 KB
testcase_02 AC 16 ms
8,564 KB
testcase_03 AC 16 ms
8,572 KB
testcase_04 AC 17 ms
8,680 KB
testcase_05 AC 16 ms
8,580 KB
testcase_06 AC 17 ms
8,540 KB
testcase_07 AC 15 ms
8,652 KB
testcase_08 AC 14 ms
8,588 KB
testcase_09 AC 15 ms
8,576 KB
testcase_10 AC 15 ms
8,480 KB
testcase_11 AC 14 ms
8,712 KB
testcase_12 AC 14 ms
8,656 KB
testcase_13 AC 15 ms
8,616 KB
testcase_14 AC 14 ms
8,680 KB
testcase_15 AC 15 ms
8,656 KB
testcase_16 AC 16 ms
8,536 KB
testcase_17 AC 15 ms
8,616 KB
testcase_18 AC 15 ms
8,704 KB
testcase_19 AC 16 ms
8,560 KB
testcase_20 AC 15 ms
8,760 KB
testcase_21 AC 15 ms
8,592 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 26 ms
8,860 KB
testcase_25 AC 26 ms
8,728 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]:
                d.append(((x + dx, y + dy)))
                visited.add((x + dx, y + dy))

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