結果

問題 No.1 道のショートカット
ユーザー Masamitsu AtarashiMasamitsu Atarashi
提出日時 2022-07-22 20:55:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 629 ms / 5,000 ms
コード長 1,293 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 10,776 KB
実行使用メモリ 9,464 KB
最終ジャッジ日時 2023-09-17 08:02:54
合計ジャッジ時間 9,075 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,612 KB
testcase_01 AC 21 ms
8,608 KB
testcase_02 AC 20 ms
8,608 KB
testcase_03 AC 20 ms
8,604 KB
testcase_04 AC 19 ms
8,596 KB
testcase_05 AC 19 ms
8,608 KB
testcase_06 AC 20 ms
8,672 KB
testcase_07 AC 20 ms
8,524 KB
testcase_08 AC 584 ms
9,136 KB
testcase_09 AC 397 ms
9,320 KB
testcase_10 AC 191 ms
9,196 KB
testcase_11 AC 199 ms
8,976 KB
testcase_12 AC 628 ms
9,464 KB
testcase_13 AC 629 ms
9,396 KB
testcase_14 AC 82 ms
8,780 KB
testcase_15 AC 193 ms
8,984 KB
testcase_16 AC 294 ms
9,252 KB
testcase_17 AC 67 ms
8,636 KB
testcase_18 AC 178 ms
9,112 KB
testcase_19 AC 252 ms
8,836 KB
testcase_20 AC 200 ms
9,060 KB
testcase_21 AC 228 ms
8,936 KB
testcase_22 AC 137 ms
8,852 KB
testcase_23 AC 180 ms
8,764 KB
testcase_24 AC 226 ms
8,832 KB
testcase_25 AC 161 ms
8,760 KB
testcase_26 AC 106 ms
8,628 KB
testcase_27 AC 339 ms
9,096 KB
testcase_28 AC 46 ms
8,584 KB
testcase_29 AC 58 ms
8,820 KB
testcase_30 AC 27 ms
8,704 KB
testcase_31 AC 38 ms
8,756 KB
testcase_32 AC 397 ms
9,264 KB
testcase_33 AC 280 ms
9,024 KB
testcase_34 AC 190 ms
8,960 KB
testcase_35 AC 23 ms
8,716 KB
testcase_36 AC 90 ms
9,120 KB
testcase_37 AC 26 ms
8,804 KB
testcase_38 AC 64 ms
8,640 KB
testcase_39 AC 289 ms
9,068 KB
testcase_40 AC 58 ms
8,960 KB
testcase_41 AC 35 ms
8,692 KB
testcase_42 AC 22 ms
8,520 KB
testcase_43 AC 276 ms
8,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# verification-helper: PROBLEM https://yukicoder.me/problems/no/1

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