結果

問題 No.1 道のショートカット
ユーザー ryusukeryusuke
提出日時 2022-01-28 20:34:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,252 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 86,668 KB
実行使用メモリ 78,932 KB
最終ジャッジ日時 2023-08-28 18:02:31
合計ジャッジ時間 9,011 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
72,140 KB
testcase_01 AC 96 ms
71,924 KB
testcase_02 AC 100 ms
72,224 KB
testcase_03 AC 99 ms
72,212 KB
testcase_04 WA -
testcase_05 AC 101 ms
71,928 KB
testcase_06 AC 100 ms
72,220 KB
testcase_07 AC 99 ms
72,236 KB
testcase_08 AC 288 ms
78,640 KB
testcase_09 AC 207 ms
78,464 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 128 ms
77,640 KB
testcase_16 WA -
testcase_17 AC 121 ms
77,336 KB
testcase_18 AC 144 ms
77,780 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 159 ms
77,716 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 151 ms
78,196 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 117 ms
77,296 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 178 ms
78,124 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 121 ms
77,680 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 104 ms
77,432 KB
testcase_43 AC 137 ms
77,892 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(lambda: INF) # d_time[i_j] := iからjへかかる時間
d_cost = defaultdict(lambda: INF) # d_cost[i_j] := iからjへかかるコスト
for i in range(v):
    d_time[f'{s[i]}_{t[i]}'] = m[i]
    d_cost[f'{s[i]}_{t[i]}'] = y[i]

# 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):
            if d_cost[f'{k}_{i}'] != INF and d_time[f'{k}_{i}'] != INF:
                if j - d_cost[f'{k}_{i}'] >= 0:
                    # k -> iに行く場合の更新路があるか考える。 (k < i)
                    dp[i][j] = min(dp[i][j], dp[k][j - d_cost[f'{k}_{i}']] + d_time[f'{k}_{i}'])

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

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