結果

問題 No.1 道のショートカット
ユーザー fmhrfmhr
提出日時 2015-04-25 03:52:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 11,044 KB
実行使用メモリ 9,004 KB
最終ジャッジ日時 2023-09-27 21:42:42
合計ジャッジ時間 2,831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,804 KB
testcase_01 AC 15 ms
7,872 KB
testcase_02 AC 16 ms
7,856 KB
testcase_03 AC 16 ms
7,804 KB
testcase_04 AC 16 ms
7,920 KB
testcase_05 AC 15 ms
7,952 KB
testcase_06 AC 16 ms
7,844 KB
testcase_07 AC 16 ms
7,872 KB
testcase_08 AC 27 ms
8,576 KB
testcase_09 AC 20 ms
8,284 KB
testcase_10 AC 25 ms
8,544 KB
testcase_11 AC 42 ms
8,248 KB
testcase_12 AC 66 ms
8,812 KB
testcase_13 AC 57 ms
9,004 KB
testcase_14 AC 17 ms
8,264 KB
testcase_15 AC 17 ms
8,280 KB
testcase_16 AC 17 ms
8,244 KB
testcase_17 AC 17 ms
8,368 KB
testcase_18 AC 16 ms
8,368 KB
testcase_19 AC 17 ms
8,312 KB
testcase_20 AC 22 ms
8,360 KB
testcase_21 AC 18 ms
8,388 KB
testcase_22 AC 16 ms
8,408 KB
testcase_23 AC 102 ms
8,296 KB
testcase_24 AC 106 ms
8,312 KB
testcase_25 AC 29 ms
8,408 KB
testcase_26 AC 22 ms
8,392 KB
testcase_27 AC 78 ms
8,256 KB
testcase_28 AC 16 ms
7,928 KB
testcase_29 AC 29 ms
8,308 KB
testcase_30 AC 18 ms
8,384 KB
testcase_31 AC 27 ms
8,296 KB
testcase_32 AC 31 ms
8,636 KB
testcase_33 AC 21 ms
8,232 KB
testcase_34 AC 70 ms
8,496 KB
testcase_35 AC 17 ms
8,404 KB
testcase_36 AC 19 ms
8,232 KB
testcase_37 AC 17 ms
8,216 KB
testcase_38 AC 16 ms
7,820 KB
testcase_39 AC 17 ms
8,460 KB
testcase_40 AC 16 ms
8,404 KB
testcase_41 AC 16 ms
8,376 KB
testcase_42 AC 16 ms
7,788 KB
testcase_43 AC 18 ms
8,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding:utf-8

def int0(n):
    return int(n)-1

N = int(input())  # 街の数
C = int(input())  # 所持金
V = int(input())  # 道の数
S = list(map(int0, input().split()))  # S->T
T = list(map(int0, input().split()))  #
Y = list(map(int, input().split()))  # cost[S][T]
M = list(map(int, input().split()))  # time[S][T]

root = [[] for i in range(N)]
for i in range(V):
    root[S[i]].append([T[i], Y[i], M[i]])
MAX = 1000 * 50 + 1
dp = [[MAX for i in range(C+1)] for j in range(N)]
dp[0][C] = 0
#  dp[ポイント][総交通費] =  総時間
for i in range(N):
    for j in range(C, 0, -1):
        if dp[i][j] == MAX:
            continue
        for kroot in root[i]:
            if kroot[1] <= j:
                dp[kroot[0]][j-kroot[1]] = min(dp[kroot[0]][j-kroot[1]], dp[i][j]+kroot[2])

ans = []
for j in range(C+1):
    if dp[N-1][j] == MAX:
        continue
    ans.append(dp[N-1][j])
if len(ans) == 0:
    print('-1')
else:
    print(min(ans))
0