結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-23 06:25:26 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,040 bytes |
コンパイル時間 | 355 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 430,604 KB |
最終ジャッジ日時 | 2024-09-30 13:05:40 |
合計ジャッジ時間 | 21,126 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 3 WA * 21 |
ソースコード
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))if i==1:print(v+j)exit()