結果

問題 No.424 立体迷路
ユーザー irumo8202irumo8202
提出日時 2022-01-22 18:56:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 910 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 8,720 KB
最終ジャッジ日時 2023-08-18 13:32:12
合計ジャッジ時間 1,983 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,500 KB
testcase_01 AC 16 ms
8,544 KB
testcase_02 AC 15 ms
8,624 KB
testcase_03 AC 15 ms
8,516 KB
testcase_04 AC 16 ms
8,540 KB
testcase_05 AC 15 ms
8,540 KB
testcase_06 AC 15 ms
8,520 KB
testcase_07 AC 15 ms
8,676 KB
testcase_08 AC 16 ms
8,600 KB
testcase_09 AC 15 ms
8,648 KB
testcase_10 AC 16 ms
8,668 KB
testcase_11 AC 15 ms
8,704 KB
testcase_12 AC 15 ms
8,720 KB
testcase_13 AC 15 ms
8,644 KB
testcase_14 AC 15 ms
8,520 KB
testcase_15 AC 17 ms
8,596 KB
testcase_16 AC 15 ms
8,560 KB
testcase_17 AC 15 ms
8,492 KB
testcase_18 AC 15 ms
8,544 KB
testcase_19 AC 18 ms
8,556 KB
testcase_20 AC 15 ms
8,596 KB
testcase_21 AC 15 ms
8,624 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 24 ms
8,568 KB
testcase_25 AC 23 ms
8,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H, W = map(int, input().split())
sy, sx, gy, gx = map(lambda x: int(x) - 1, input().split())

S = [list(map(int, input())) for _ in range(H)]

visited = [[False] * W for _ in range(H)]
visited[sy][sx] = True

direction = [(-1, 0), (0, 1), (1, 0), (0, -1), (-2, 0), (0, 2), (2, 0), (0, -2)]

que = deque([(sy, sx)])

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

    for dy, dx in direction:
        ny, nx = y + dy, x + dx
        if 0 <= ny < H and 0 <= nx < W:
            if visited[ny][nx]:
                continue
            flg = False
            if abs(dy + dx) == 2:
                if S[ny][nx] == S[y][x]:
                    flg = True
            else:
                if abs(S[ny][nx] - S[y][x]) <= 1:
                    flg = True
            if flg:
                visited[ny][nx] = True
                que.append((ny, nx))


print("YES" if visited[gy][gx] else "NO")
0