結果
| 問題 | No.2695 Warp Zone |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-01 14:39:56 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 881 bytes |
| 記録 | |
| コンパイル時間 | 176 ms |
| コンパイル使用メモリ | 85,760 KB |
| 実行使用メモリ | 884,220 KB |
| 最終ジャッジ日時 | 2026-05-28 11:13:59 |
| 合計ジャッジ時間 | 6,320 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 1 MLE * 1 -- * 22 |
ソースコード
from heapq import heapify, heappop, heappush
H, W, N = map(int, input().split())
D = {}
for _ in range(N):
a, b, c, d = map(int, input().split())
a -= 1; b -= 1; c -= 1; d -= 1
D[(a, b)] = (c, d)
dist = [10 ** 18] * (H * W)
dist[0] = 0
pq = [(0, 0)]
heapify(pq)
dx = [-1, 0, 0, 1]
dy = [0, -1, 1, 0]
while len(pq) > 0:
d, id = heappop(pq)
x, y = id // W, id % W
if (x, y) in D:
v, w = D[(x, y)]
if dist[v * W + w] > dist[id] + 1:
dist[v * W + w] = dist[id] + 1
heappush(pq, (dist[v * W + w], v * W + w))
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 > nx or nx >= H or 0 > ny or ny >= W: continue
if dist[nx * W + ny] > dist[id] + 1:
dist[nx * W + ny] = dist[id] + 1
heappush(pq, (dist[nx * W + ny], nx * W + ny))
print(dist[(H - 1) * W + (W - 1)])