結果

問題 No.1 道のショートカット
ユーザー ryusukeryusuke
提出日時 2022-01-28 20:30:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,464 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 87,344 KB
実行使用メモリ 79,616 KB
最終ジャッジ日時 2023-08-28 17:58:32
合計ジャッジ時間 10,377 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
72,328 KB
testcase_01 AC 98 ms
72,380 KB
testcase_02 AC 102 ms
72,468 KB
testcase_03 AC 92 ms
72,464 KB
testcase_04 WA -
testcase_05 AC 91 ms
72,268 KB
testcase_06 AC 91 ms
72,412 KB
testcase_07 AC 94 ms
72,396 KB
testcase_08 AC 436 ms
79,532 KB
testcase_09 AC 285 ms
78,984 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 141 ms
77,932 KB
testcase_16 WA -
testcase_17 AC 130 ms
77,996 KB
testcase_18 AC 170 ms
78,336 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 196 ms
78,132 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 185 ms
78,480 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 126 ms
78,260 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 230 ms
79,036 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 147 ms
77,952 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 109 ms
77,728 KB
testcase_43 AC 176 ms
78,136 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:
                    dp[i][j] = min(dp[i][j], dp[k][j - d_cost[f'{k}_{i}']] + d_time[f'{k}_{i}'])
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:
                    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