結果

問題 No.1 道のショートカット
ユーザー ryusukeryusuke
提出日時 2022-01-29 15:22:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,300 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 79,404 KB
最終ジャッジ日時 2023-08-30 14:19:10
合計ジャッジ時間 9,455 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,804 KB
testcase_01 AC 97 ms
71,988 KB
testcase_02 AC 96 ms
72,172 KB
testcase_03 AC 100 ms
72,056 KB
testcase_04 AC 97 ms
71,116 KB
testcase_05 AC 97 ms
71,796 KB
testcase_06 AC 97 ms
71,704 KB
testcase_07 AC 101 ms
71,676 KB
testcase_08 AC 339 ms
78,676 KB
testcase_09 AC 216 ms
78,144 KB
testcase_10 WA -
testcase_11 AC 172 ms
78,636 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 127 ms
77,380 KB
testcase_16 AC 170 ms
78,064 KB
testcase_17 AC 118 ms
77,256 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 156 ms
78,152 KB
testcase_21 AC 160 ms
77,760 KB
testcase_22 AC 140 ms
77,572 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 151 ms
77,968 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 119 ms
77,252 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 182 ms
78,204 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 116 ms
77,508 KB
testcase_38 AC 125 ms
77,256 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 119 ms
77,420 KB
testcase_42 AC 104 ms
77,220 KB
testcase_43 AC 141 ms
77,492 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):
    if y[i] < d_cost[f'{s[i]}_{t[i]}']:
        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