結果

問題 No.1 道のショートカット
ユーザー n_knuu
提出日時 2015-05-07 18:05:17
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 697 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-07-20 16:13:19
合計ジャッジ時間 3,600 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

from queue import PriorityQueue as PQueue
N = int(input())
C = int(input())
V = int(input())
S = list(map(lambda x: int(x)-1, input().split()))
T = list(map(lambda x: int(x)-1, input().split()))
Y = list(map(int, input().split()))
M = list(map(int, input().split()))
E = [[] for _ in range(N)]
for f, t, cost, time in zip(S, T, Y, M):
    E[t].append((f, cost, time))
INF = 10**7
dp = [[INF] * (C+1) for _ in range(N)]
for i in range(C+1):
    dp[0][i] = 0
for t in range(N):
    for j in range(C+1):
        for f, cost, time in E[t]:
            if j >= cost and dp[t][j] > dp[f][j-cost] + time:
                dp[t][j] = dp[f][j-cost] + time
print(min(dp[N-1]) if min(dp[N-1]) != INF else -1)
0