結果
問題 | No.2695 Warp Zone |
ユーザー |
|
提出日時 | 2024-03-22 22:06:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,146 bytes |
コンパイル時間 | 389 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 178,432 KB |
最終ジャッジ日時 | 2024-09-30 11:36:33 |
合計ジャッジ時間 | 5,472 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 6 |
ソースコード
import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd h,w,n = map(int,input().split()) za = [list(map(int,input().split())) for i in range(n)] graph = [[] for i in range(n+3)] for i in range(n): ai,bi,ci,di = za[i] for j in range(n): if i== j: continue aj,bj,cj,dj = za[j] dis = abs(ci-aj) + abs(di-bj) graph[i].append((j, dis+1)) graph[j].append((i, dis+1)) graph[n].append((i, ai+bi-2+1)) graph[i].append((n+1, abs(h-ci)+abs(w-di))) graph[n].append((n+1, h+w-2)) #ダイクストラ法 def dijkstra(s,n): # sがスタート、nが頂点数 INF = 10**15 dist = [INF]*(n+1) que = [(0,s)] dist[s] = 0 while que: c,crr = heappop(que) if c > dist[crr]: continue for nxt, cost in graph[crr]: if dist[crr] + cost < dist[nxt]: dist[nxt] = dist[crr] + cost heappush(que,(dist[nxt],nxt)) return dist d = dijkstra(n,n+2) print(d[n+1])