結果

問題 No.424 立体迷路
ユーザー tokizotokizo
提出日時 2019-02-01 18:11:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,088 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 192,000 KB
最終ジャッジ日時 2024-05-02 20:36:57
合計ジャッジ時間 5,332 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
17,792 KB
testcase_01 WA -
testcase_02 AC 44 ms
12,416 KB
testcase_03 AC 42 ms
12,416 KB
testcase_04 AC 46 ms
12,416 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 43 ms
12,288 KB
testcase_11 AC 42 ms
12,416 KB
testcase_12 AC 41 ms
12,288 KB
testcase_13 AC 42 ms
12,288 KB
testcase_14 AC 42 ms
12,288 KB
testcase_15 WA -
testcase_16 AC 46 ms
12,288 KB
testcase_17 AC 44 ms
12,288 KB
testcase_18 AC 46 ms
12,288 KB
testcase_19 AC 45 ms
12,416 KB
testcase_20 AC 45 ms
12,416 KB
testcase_21 AC 41 ms
12,416 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import pprint
from collections import deque

def main():
    h, w = map(int, input().split())
    sx, sy, gx, gy = map(int, input().split())
    sx -= 1
    sy -= 1
    gx -= 1
    gy -= 1

    B = []
    for i in range(h):
        B.append(list(map(int, list(input()))))

    seen = [[False for _ in range(w)] for _ in range(h)]

    dx = [-1, 1, 0, 0, -2, 2, 0, 0]
    dy = [0, 0, -1, 1, 0, 0, -2, 2]

    q = deque()
    q.append((sx, sy))
    while q:
        x, y = q.popleft()
        seen[x][y] = True
        for i in range(8):
            nx = x + dx[i]
            ny = y + dy[i]
            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                continue
            if seen[nx][ny]:
                continue
            if nx == gx and ny == gy:
                print("YES")
                exit()
            if i < 4:
                if abs(B[x][y] - B[nx][ny] > 1):
                    continue
            else:
                if B[x][y] != B[nx][ny]:
                    continue
            q.append((nx, ny))
    print("NO")


if __name__ == "__main__":
    main()
0