結果

問題 No.424 立体迷路
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-28 20:36:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-12 10:16:52
合計ジャッジ時間 1,711 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 25 ms
10,880 KB
testcase_02 AC 25 ms
10,880 KB
testcase_03 AC 25 ms
10,880 KB
testcase_04 AC 26 ms
11,008 KB
testcase_05 AC 27 ms
10,880 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 29 ms
11,008 KB
testcase_08 AC 28 ms
10,880 KB
testcase_09 AC 26 ms
10,880 KB
testcase_10 AC 27 ms
10,880 KB
testcase_11 AC 25 ms
10,880 KB
testcase_12 AC 25 ms
10,880 KB
testcase_13 AC 25 ms
10,880 KB
testcase_14 AC 24 ms
10,880 KB
testcase_15 AC 25 ms
10,880 KB
testcase_16 AC 24 ms
10,880 KB
testcase_17 AC 24 ms
10,880 KB
testcase_18 AC 25 ms
11,008 KB
testcase_19 AC 24 ms
10,880 KB
testcase_20 AC 24 ms
10,880 KB
testcase_21 AC 24 ms
10,880 KB
testcase_22 AC 25 ms
10,880 KB
testcase_23 AC 24 ms
10,880 KB
testcase_24 AC 36 ms
10,880 KB
testcase_25 AC 35 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
G = [tuple(map(int, list(input()))) for _ in range(H)]

DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]

vis = [[0] * W for _ in range(H)]
vis[sx][sy] = 1
q = [(sx, sy)]
while q:
    x, y = q.pop()
    now = G[x][y]
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W:
            if not vis[nx][ny]:
                nxt = G[nx][ny]
                if abs(nxt - now) <= 1:
                    vis[nx][ny] = 1
                    q.append((nx, ny))
        nnx = nx + dx
        nny = ny + dy
        if 0 <= nnx < H and 0 <= nny < W:
            if not vis[nnx][nny]:
                nxt = G[nx][ny]
                nxtnxt = G[nnx][nny]
                if now == nxtnxt and now > nxt:
                    vis[nnx][nny] = 1
                    q.append((nnx, nny))

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