結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-22 23:05:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 197 ms / 2,000 ms |
コード長 | 737 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 81,880 KB |
実行使用メモリ | 78,592 KB |
最終ジャッジ日時 | 2024-09-30 12:23:37 |
合計ジャッジ時間 | 4,168 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
import sys input = sys.stdin.readline from operator import itemgetter from heapq import heappop,heappush H,W,N=map(int,input().split()) WA=[list(map(int,input().split())) for i in range(N)] WA=[[1,1,1,1]]+WA+[[H,W,H,W]] DP=[1<<63]*len(WA) WA.sort(key=itemgetter(0)) WA.sort(key=itemgetter(1)) DP[0]=0 Q=[(0,0)] while Q: time,ind=heappop(Q) if DP[ind]!=time: continue a,b,c,d=WA[ind] for j in range(len(WA)): e,f,g,h=WA[j] dis=abs(e-a)+abs(f-b) if DP[j]>DP[ind]+dis: DP[j]=DP[ind]+dis heappush(Q,(DP[j],j)) dis=abs(e-c)+abs(f-d) if DP[j]>DP[ind]+dis+1: DP[j]=DP[ind]+dis+1 heappush(Q,(DP[j],j)) print(DP[-1])