結果

問題 No.1 道のショートカット
ユーザー ryusukeryusuke
提出日時 2022-01-29 16:01:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 257 ms / 5,000 ms
コード長 1,226 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 79,276 KB
最終ジャッジ日時 2023-08-30 15:33:42
合計ジャッジ時間 9,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,968 KB
testcase_01 AC 95 ms
71,492 KB
testcase_02 AC 97 ms
71,612 KB
testcase_03 AC 98 ms
72,460 KB
testcase_04 AC 95 ms
71,612 KB
testcase_05 AC 95 ms
71,588 KB
testcase_06 AC 99 ms
72,200 KB
testcase_07 AC 100 ms
72,564 KB
testcase_08 AC 234 ms
79,056 KB
testcase_09 AC 214 ms
79,136 KB
testcase_10 AC 177 ms
78,976 KB
testcase_11 AC 172 ms
78,972 KB
testcase_12 AC 257 ms
79,208 KB
testcase_13 AC 250 ms
79,092 KB
testcase_14 AC 142 ms
77,740 KB
testcase_15 AC 147 ms
78,208 KB
testcase_16 AC 197 ms
79,036 KB
testcase_17 AC 135 ms
77,788 KB
testcase_18 AC 172 ms
78,544 KB
testcase_19 AC 194 ms
78,444 KB
testcase_20 AC 180 ms
78,872 KB
testcase_21 AC 182 ms
78,660 KB
testcase_22 AC 156 ms
77,756 KB
testcase_23 AC 143 ms
78,524 KB
testcase_24 AC 162 ms
78,724 KB
testcase_25 AC 162 ms
78,428 KB
testcase_26 AC 141 ms
77,708 KB
testcase_27 AC 199 ms
79,276 KB
testcase_28 AC 139 ms
77,420 KB
testcase_29 AC 142 ms
78,776 KB
testcase_30 AC 116 ms
77,944 KB
testcase_31 AC 117 ms
78,012 KB
testcase_32 AC 207 ms
78,844 KB
testcase_33 AC 182 ms
78,584 KB
testcase_34 AC 163 ms
79,196 KB
testcase_35 AC 109 ms
77,712 KB
testcase_36 AC 142 ms
78,364 KB
testcase_37 AC 120 ms
77,776 KB
testcase_38 AC 136 ms
77,992 KB
testcase_39 AC 193 ms
78,672 KB
testcase_40 AC 135 ms
78,560 KB
testcase_41 AC 123 ms
78,008 KB
testcase_42 AC 108 ms
77,588 KB
testcase_43 AC 169 ms
78,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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