結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-23 06:20:10 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,010 bytes |
コンパイル時間 | 291 ms |
コンパイル使用メモリ | 82,332 KB |
実行使用メモリ | 432,144 KB |
最終ジャッジ日時 | 2024-09-30 13:05:13 |
合計ジャッジ時間 | 24,374 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 TLE * 1 |
ソースコード
import heapqh,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]=0g=[[] 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:continueg[2*i+2].append([2*j+2,dist(wps[i],wps[j])])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]:continuefor i,j in g[w]:if d[i]>v+j:d[i]=v+jheapq.heappush(hq,(v+j,i))print(d[1])