結果

問題 No.1 道のショートカット
コンテスト
ユーザー persimmon-persimmon
提出日時 2022-04-01 14:56:43
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 810 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 244 ms
コンパイル使用メモリ 85,240 KB
実行使用メモリ 75,520 KB
最終ジャッジ日時 2026-05-13 15:44:48
合計ジャッジ時間 3,462 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
0