結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2020-02-28 16:24:33 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 122 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-10-13 16:26:20 |
合計ジャッジ時間 | 1,763 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#!/usr/bin/env python3# %%import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlines# %%H, W = map(int, readline().split())H += 4W += 4sx, sy, gx, gy = map(lambda x: int(x) + 1, readline().split())INF = 20A = [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 * Wgraph = [[] for _ in range(N)]s = sx * W + syg = gx * W + gy# %%for i in range(2, H - 2):for j in range(2, W - 2):v = i * W + jfor 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] * Nvisited[s] = Truestack = [s]while stack:v = stack.pop()for w in graph[v]:if visited[w]:continuestack.append(w)visited[w] = True# %%answer = 'YES' if visited[g] else 'NO'print(answer)