結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2021-01-11 20:41:11 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 226 ms / 5,000 ms |
コード長 | 729 bytes |
コンパイル時間 | 101 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-11-21 09:24:27 |
合計ジャッジ時間 | 4,495 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#dp[j][k] = 町jに所持金k円で行く最短時間 N = int(input()) C = int(input()) V = int(input()) lsS = list(map(int,input().split())) lsT = list(map(int,input().split())) lsY = list(map(int,input().split())) lsM = list(map(int,input().split())) lsedge = [] for i in range(V): lsedge.append((lsS[i],lsT[i],lsY[i],lsM[i])) lsedge.sort() dp = [[float('INF')]*(C+1) for i in range(N+1) ] dp[1][C] = 0 for i in range(1,V+1): from1 = lsedge[i-1][0] to = lsedge[i-1][1] cost = lsedge[i-1][2] time = lsedge[i-1][3] for k in range(C+1): if k - cost >= 0: dp[to][k-cost] = min(dp[to][k-cost],dp[from1][k]+time) if min(dp[N]) == float('INF'): print(-1) else: print(min(dp[N]))