結果

問題 No.1 道のショートカット
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-01 14:56:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 810 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-04-29 22:47:01
合計ジャッジ時間 3,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,608 KB
testcase_01 AC 39 ms
52,480 KB
testcase_02 AC 40 ms
52,608 KB
testcase_03 AC 39 ms
52,736 KB
testcase_04 AC 40 ms
52,608 KB
testcase_05 AC 43 ms
52,608 KB
testcase_06 AC 37 ms
52,736 KB
testcase_07 AC 36 ms
52,864 KB
testcase_08 AC 61 ms
70,912 KB
testcase_09 AC 44 ms
61,696 KB
testcase_10 AC 57 ms
67,072 KB
testcase_11 AC 62 ms
70,912 KB
testcase_12 AC 69 ms
74,736 KB
testcase_13 AC 74 ms
76,672 KB
testcase_14 AC 35 ms
53,120 KB
testcase_15 AC 36 ms
52,736 KB
testcase_16 AC 39 ms
58,624 KB
testcase_17 AC 36 ms
53,120 KB
testcase_18 AC 35 ms
52,736 KB
testcase_19 AC 34 ms
52,864 KB
testcase_20 AC 43 ms
60,544 KB
testcase_21 AC 37 ms
53,376 KB
testcase_22 AC 36 ms
52,608 KB
testcase_23 AC 56 ms
68,864 KB
testcase_24 AC 52 ms
66,560 KB
testcase_25 AC 41 ms
60,672 KB
testcase_26 AC 36 ms
53,888 KB
testcase_27 AC 62 ms
71,168 KB
testcase_28 AC 36 ms
52,736 KB
testcase_29 AC 58 ms
68,480 KB
testcase_30 AC 44 ms
61,312 KB
testcase_31 AC 48 ms
63,232 KB
testcase_32 AC 54 ms
67,200 KB
testcase_33 AC 45 ms
61,824 KB
testcase_34 AC 68 ms
73,344 KB
testcase_35 AC 40 ms
59,776 KB
testcase_36 AC 49 ms
63,488 KB
testcase_37 AC 42 ms
61,440 KB
testcase_38 AC 37 ms
52,736 KB
testcase_39 AC 38 ms
52,864 KB
testcase_40 AC 41 ms
59,008 KB
testcase_41 AC 36 ms
52,992 KB
testcase_42 AC 38 ms
52,608 KB
testcase_43 AC 35 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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