結果

問題 No.424 立体迷路
ユーザー maspymaspy
提出日時 2020-02-28 16:24:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-21 17:35:04
合計ジャッジ時間 2,006 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# %%
H, W = map(int, readline().split())
H += 4
W += 4
sx, sy, gx, gy = map(lambda x: int(x) + 1, readline().split())
INF = 20
A = [INF] * (H * W)
for h in range(2, H - 2):
    A[h * W + 2:(h + 1) * W - 2] = map(int, readline().decode().rstrip())

# %%
N = H * W
graph = [[] for _ in range(N)]
s = sx * W + sy
g = gx * W + gy


# %%
for i in range(2, H - 2):
    for j in range(2, W - 2):
        v = i * W + j
        for dx in (1, -1, W, -W):
            if A[v] - A[v + dx] in (-1, 0, 1):
                graph[v].append(v + dx)
            if A[v] == A[v + dx + dx] and A[v] > A[v + dx]:
                graph[v].append(v + dx + dx)

# %%
visited = [False] * N
visited[s] = True
stack = [s]
while stack:
    v = stack.pop()
    for w in graph[v]:
        if visited[w]:
            continue
        stack.append(w)
        visited[w] = True


# %%
answer = 'YES' if visited[g] else 'NO'
print(answer)
0