結果

問題 No.1 道のショートカット
ユーザー ryusukeryusuke
提出日時 2022-01-29 16:01:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 193 ms / 5,000 ms
コード長 1,226 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 78,224 KB
最終ジャッジ日時 2025-01-02 07:10:44
合計ジャッジ時間 5,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
56,180 KB
testcase_01 AC 38 ms
55,704 KB
testcase_02 AC 38 ms
55,352 KB
testcase_03 AC 39 ms
56,472 KB
testcase_04 AC 39 ms
54,248 KB
testcase_05 AC 39 ms
55,648 KB
testcase_06 AC 40 ms
56,500 KB
testcase_07 AC 41 ms
57,256 KB
testcase_08 AC 169 ms
77,800 KB
testcase_09 AC 148 ms
77,628 KB
testcase_10 AC 110 ms
77,596 KB
testcase_11 AC 115 ms
77,680 KB
testcase_12 AC 193 ms
78,224 KB
testcase_13 AC 182 ms
78,136 KB
testcase_14 AC 84 ms
77,044 KB
testcase_15 AC 92 ms
76,744 KB
testcase_16 AC 140 ms
77,900 KB
testcase_17 AC 77 ms
76,748 KB
testcase_18 AC 117 ms
77,276 KB
testcase_19 AC 127 ms
77,588 KB
testcase_20 AC 116 ms
77,600 KB
testcase_21 AC 118 ms
77,368 KB
testcase_22 AC 99 ms
77,100 KB
testcase_23 AC 85 ms
77,220 KB
testcase_24 AC 101 ms
77,388 KB
testcase_25 AC 98 ms
77,224 KB
testcase_26 AC 87 ms
76,760 KB
testcase_27 AC 144 ms
77,892 KB
testcase_28 AC 77 ms
76,980 KB
testcase_29 AC 86 ms
77,444 KB
testcase_30 AC 56 ms
69,952 KB
testcase_31 AC 58 ms
70,524 KB
testcase_32 AC 147 ms
77,556 KB
testcase_33 AC 121 ms
77,248 KB
testcase_34 AC 103 ms
77,252 KB
testcase_35 AC 49 ms
66,972 KB
testcase_36 AC 86 ms
77,276 KB
testcase_37 AC 63 ms
74,584 KB
testcase_38 AC 82 ms
76,924 KB
testcase_39 AC 140 ms
77,352 KB
testcase_40 AC 80 ms
77,436 KB
testcase_41 AC 71 ms
76,732 KB
testcase_42 AC 52 ms
68,192 KB
testcase_43 AC 116 ms
77,108 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