結果

問題 No.1 道のショートカット
ユーザー Masamitsu AtarashiMasamitsu Atarashi
提出日時 2022-07-22 20:54:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 260 ms / 5,000 ms
コード長 1,293 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 79,356 KB
最終ジャッジ日時 2023-09-17 08:02:33
合計ジャッジ時間 8,530 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,752 KB
testcase_01 AC 96 ms
71,560 KB
testcase_02 AC 97 ms
71,876 KB
testcase_03 AC 100 ms
72,148 KB
testcase_04 AC 96 ms
71,744 KB
testcase_05 AC 100 ms
71,372 KB
testcase_06 AC 100 ms
72,004 KB
testcase_07 AC 104 ms
72,340 KB
testcase_08 AC 235 ms
79,084 KB
testcase_09 AC 211 ms
79,100 KB
testcase_10 AC 177 ms
79,020 KB
testcase_11 AC 176 ms
79,168 KB
testcase_12 AC 260 ms
79,256 KB
testcase_13 AC 254 ms
79,356 KB
testcase_14 AC 141 ms
78,044 KB
testcase_15 AC 147 ms
78,072 KB
testcase_16 AC 196 ms
78,800 KB
testcase_17 AC 136 ms
77,644 KB
testcase_18 AC 175 ms
78,632 KB
testcase_19 AC 189 ms
78,432 KB
testcase_20 AC 174 ms
79,056 KB
testcase_21 AC 178 ms
78,292 KB
testcase_22 AC 156 ms
78,092 KB
testcase_23 AC 143 ms
78,596 KB
testcase_24 AC 161 ms
78,740 KB
testcase_25 AC 163 ms
78,512 KB
testcase_26 AC 145 ms
77,892 KB
testcase_27 AC 207 ms
79,108 KB
testcase_28 AC 130 ms
77,476 KB
testcase_29 AC 140 ms
78,708 KB
testcase_30 AC 115 ms
77,748 KB
testcase_31 AC 116 ms
77,952 KB
testcase_32 AC 203 ms
78,880 KB
testcase_33 AC 178 ms
78,840 KB
testcase_34 AC 160 ms
78,924 KB
testcase_35 AC 109 ms
77,412 KB
testcase_36 AC 142 ms
78,500 KB
testcase_37 AC 119 ms
78,148 KB
testcase_38 AC 137 ms
78,184 KB
testcase_39 AC 197 ms
78,556 KB
testcase_40 AC 136 ms
78,740 KB
testcase_41 AC 127 ms
77,460 KB
testcase_42 AC 110 ms
77,472 KB
testcase_43 AC 171 ms
78,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# verification-helper: PROBLEM https://yukicoder.me/problems/no/1

from collections import defaultdict

n = int(input())
c = int(input())
v = int(input())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
y = list(map(int, input().split()))
m = list(map(int, input().split()))

INF = 10 ** 18
d_time = defaultdict(list) # d_time[i_j] := iからjへかかる時間
d_cost = defaultdict(list) # d_cost[i_j] := iからjへかかるコスト

for i in range(v):
    d_time[f'{s[i]}_{t[i]}'].append(m[i])
    d_cost[f'{s[i]}_{t[i]}'].append(y[i])
#print(d_time)
#print(d_cost)
# dp[i][j] := i番目の町にいて、かかったコストがjである時のかかった時間の最小値
# dp[i][j] = min(dp[i][j], dp[k][j - y[j]] + c[j]) (1 <= k < i)

dp = [[INF] * (c + 1) for _ in range(n + 1)]
for j in range(c + 1):
    dp[1][j] = 0

for i in range(1, n + 1):
    for k in range(1, i):
        for j in range(c + 1):
            for p, q in zip(d_cost[f'{k}_{i}'], d_time[f'{k}_{i}']):
                if j - p >= 0:
                    # k -> iに行く場合の更新路があるか考える。 (k < i)
                    dp[i][j] = min(dp[i][j], dp[k][j - p] + q)

ans = INF
for j in range(c + 1):
    ans = min(ans, dp[-1][j])

print(ans) if ans != INF else print(-1)
0