結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2022-04-01 14:56:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 77 ms / 5,000 ms |
コード長 | 810 bytes |
コンパイル時間 | 439 ms |
コンパイル使用メモリ | 82,376 KB |
実行使用メモリ | 76,704 KB |
最終ジャッジ日時 | 2024-11-19 07:42:30 |
合計ジャッジ時間 | 3,882 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
from heapq import heappush,heappop n=int(input()) c=int(input()) v=int(input()) ss=list(map(int,input().split())) tt=list(map(int,input().split())) yy=list(map(int,input().split())) mm=list(map(int,input().split())) g=[[] for _ in range(n)] for s,t,y,m in zip(ss,tt,yy,mm): s-=1 t-=1 g[s].append([t,y,m]) inf=float('inf') dp=[[inf]*(c+1) for _ in range(n)] # dp[i][c]:残金cの状態で街iに到達する最小時間 q=[[0,0,c]]# 経過時間、街idx、残金 while q: tm,ct,mn=heappop(q) if dp[ct][mn]<tm:continue for nct,dmn,dtm in g[ct]: if mn-dmn<0:continue if dp[nct][dmn]>tm+dtm: dp[nct][dmn]=tm+dtm heappush(q,[tm+dtm,nct,mn-dmn]) ans=inf for mn in range(c+1): ans=min(ans,dp[-1][mn]) if ans!=inf: print(ans) else: print(-1)