結果

問題 No.1 道のショートカット
ユーザー ryusukeryusuke
提出日時 2022-01-29 01:43:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,314 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 78,824 KB
最終ジャッジ日時 2023-08-29 01:26:54
合計ジャッジ時間 9,434 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
72,156 KB
testcase_01 AC 95 ms
72,484 KB
testcase_02 AC 95 ms
72,412 KB
testcase_03 AC 94 ms
72,024 KB
testcase_04 WA -
testcase_05 AC 94 ms
72,372 KB
testcase_06 AC 94 ms
72,216 KB
testcase_07 AC 95 ms
72,424 KB
testcase_08 AC 294 ms
78,796 KB
testcase_09 AC 209 ms
78,720 KB
testcase_10 AC 165 ms
78,632 KB
testcase_11 AC 174 ms
78,476 KB
testcase_12 WA -
testcase_13 AC 277 ms
78,824 KB
testcase_14 AC 127 ms
77,464 KB
testcase_15 AC 125 ms
77,540 KB
testcase_16 WA -
testcase_17 AC 118 ms
77,648 KB
testcase_18 AC 137 ms
77,772 KB
testcase_19 AC 152 ms
77,984 KB
testcase_20 AC 149 ms
78,540 KB
testcase_21 AC 153 ms
77,788 KB
testcase_22 AC 137 ms
77,652 KB
testcase_23 AC 153 ms
78,244 KB
testcase_24 AC 155 ms
78,248 KB
testcase_25 AC 149 ms
78,060 KB
testcase_26 AC 131 ms
77,652 KB
testcase_27 AC 203 ms
78,492 KB
testcase_28 AC 115 ms
77,432 KB
testcase_29 AC 139 ms
78,456 KB
testcase_30 WA -
testcase_31 AC 104 ms
76,860 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 101 ms
77,012 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 159 ms
77,812 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 100 ms
77,336 KB
testcase_43 AC 134 ms
77,716 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]}'] = min(m[i], d_time[f'{s[i]}_{t[i]}'])
    d_cost[f'{s[i]}_{t[i]}'] = min(y[i], d_cost[f'{s[i]}_{t[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