結果

問題 No.1 道のショートカット
ユーザー kohei2019kohei2019
提出日時 2021-01-11 20:41:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 9,000 KB
最終ジャッジ日時 2023-08-13 13:43:02
合計ジャッジ時間 5,087 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,864 KB
testcase_01 AC 16 ms
7,768 KB
testcase_02 AC 16 ms
7,740 KB
testcase_03 AC 15 ms
7,956 KB
testcase_04 AC 16 ms
7,860 KB
testcase_05 AC 16 ms
7,812 KB
testcase_06 AC 16 ms
7,768 KB
testcase_07 AC 16 ms
7,820 KB
testcase_08 AC 145 ms
8,488 KB
testcase_09 AC 85 ms
8,356 KB
testcase_10 AC 54 ms
8,504 KB
testcase_11 AC 78 ms
8,244 KB
testcase_12 AC 194 ms
8,824 KB
testcase_13 AC 189 ms
9,000 KB
testcase_14 AC 25 ms
8,304 KB
testcase_15 AC 16 ms
8,344 KB
testcase_16 AC 40 ms
8,400 KB
testcase_17 AC 16 ms
8,260 KB
testcase_18 AC 24 ms
8,216 KB
testcase_19 AC 33 ms
8,392 KB
testcase_20 AC 37 ms
8,320 KB
testcase_21 AC 46 ms
8,204 KB
testcase_22 AC 29 ms
8,344 KB
testcase_23 AC 135 ms
8,360 KB
testcase_24 AC 157 ms
8,244 KB
testcase_25 AC 64 ms
8,364 KB
testcase_26 AC 48 ms
8,372 KB
testcase_27 AC 123 ms
8,308 KB
testcase_28 AC 18 ms
7,920 KB
testcase_29 AC 39 ms
8,220 KB
testcase_30 AC 20 ms
8,404 KB
testcase_31 AC 32 ms
8,236 KB
testcase_32 AC 107 ms
8,508 KB
testcase_33 AC 75 ms
8,248 KB
testcase_34 AC 133 ms
8,632 KB
testcase_35 AC 20 ms
8,288 KB
testcase_36 AC 35 ms
8,252 KB
testcase_37 AC 20 ms
8,160 KB
testcase_38 AC 20 ms
7,800 KB
testcase_39 AC 36 ms
8,380 KB
testcase_40 AC 21 ms
8,380 KB
testcase_41 AC 18 ms
7,920 KB
testcase_42 AC 16 ms
7,776 KB
testcase_43 AC 17 ms
8,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#dp[j][k] = 町jに所持金k円で行く最短時間
N = int(input())
C = int(input())
V = int(input())
lsS = list(map(int,input().split()))
lsT = list(map(int,input().split()))
lsY = list(map(int,input().split()))
lsM = list(map(int,input().split()))
lsedge = []
for i in range(V):
    lsedge.append((lsS[i],lsT[i],lsY[i],lsM[i]))
lsedge.sort()
dp = [[float('INF')]*(C+1) for i in range(N+1) ]
dp[1][C] = 0
for i in range(1,V+1):
    from1 = lsedge[i-1][0]
    to = lsedge[i-1][1]
    cost = lsedge[i-1][2]
    time = lsedge[i-1][3]
    for k in range(C+1):
        if k - cost >= 0:
            dp[to][k-cost] = min(dp[to][k-cost],dp[from1][k]+time)
if min(dp[N]) == float('INF'):
    print(-1)
else:
    print(min(dp[N]))
0