結果
問題 | No.2695 Warp Zone |
ユーザー |
|
提出日時 | 2024-03-22 22:46:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 775 ms / 2,000 ms |
コード長 | 1,014 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 82,112 KB |
最終ジャッジ日時 | 2024-09-30 12:11:09 |
合計ジャッジ時間 | 10,037 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
from heapq import heapify, heappop, heappushfrom collections import defaultdictH, W, N = map(int, input().split())Warp = [list(map(int, input().split())) for _ in range(N)]INF = 1 << 60dist = defaultdict(lambda: INF)dist[1, 1] = 0q = [(0, 1, 1)]while q:d, vx, vy = heappop(q)if d > dist[vx, vy]:continuefor i in range(N):a, b, c, d = Warp[i]if dist[a, b] > dist[vx, vy] + abs(vx - a) + abs(vy - b):dist[a, b] = dist[vx, vy] + abs(vx - a) + abs(vy - b)heappush(q, (dist[a, b], a, b))if dist[c, d] > dist[a, b] + 1:dist[c, d] = dist[a, b] + 1heappush(q, (dist[c, d], c, d))if dist[c, d] > dist[vx, vy] + abs(vx - c) + abs(vy - d):dist[c, d] = dist[vx, vy] + abs(vx - c) + abs(vy - d)heappush(q, (dist[c, d], c, d))if dist[H, W] > dist[vx, vy] + abs(vx - H) + abs(vy - W):dist[H, W] = dist[vx, vy] + abs(vx - H) + abs(vy - W)print(dist[H, W])