結果
問題 |
No.2695 Warp Zone
|
ユーザー |
![]() |
提出日時 | 2024-03-23 06:29:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,146 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 82,224 KB |
実行使用メモリ | 252,560 KB |
最終ジャッジ日時 | 2024-09-30 13:05:44 |
合計ジャッジ時間 | 3,979 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 3 TLE * 1 -- * 20 |
ソースコード
import heapq h,w,n=map(int,input().split()) wps=[] wpt=[] for i in range(n): a,b,c,d=map(int,input().split()) wps.append([a,b]) wpt.append([c,d]) def dist(x,y): return (abs(x[0]-y[0])+abs(x[1]-y[1])) d=[10**18]*(2+n*2) d[0]=0 g=[[] for _ in range(2+n*2)] for i in range(n): g[0].append([2*i+2,dist([1,1],wps[i])]) g[0].append([2*i+3,dist([1,1],wpt[i])]) g[0].append([1,dist([1,1],[h,w])]) for i in range(n): g[2*i+2].append([2*i+3,1]) g[2*i+3].append([2*i+2,dist(wps[i],wpt[i])]) g[2*i+2].append([1,dist(wps[i],[h,w])]) g[2*i+3].append([1,dist(wpt[i],[h,w])]) for j in range(n): if i==j: continue k=dist(wpt[i],wps[j]) if 1+dist(wps[i],wps[j])<k: g[2*i+2].append([2*j+2,dist(wps[i],wps[j])]) k=dist(wpt[i],wpt[j]) if 1+dist(wps[i],wpt[j])<k: g[2*i+2].append([2*j+3,dist(wps[i],wpt[j])]) g[2*i+3].append([2*j+2,dist(wpt[i],wps[j])]) g[2*i+3].append([2*j+3,dist(wpt[i],wpt[j])]) hq=[(0,0)] while hq: v,w=heapq.heappop(hq) if v>d[w]: continue if w==1: print(v) exit() for i,j in g[w]: if d[i]>v+j: d[i]=v+j heapq.heappush(hq,(v+j,i))