結果

問題 No.1 道のショートカット
ユーザー しらっ亭しらっ亭
提出日時 2015-07-09 21:16:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 1,082 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 9,144 KB
最終ジャッジ日時 2023-09-27 21:46:20
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,308 KB
testcase_01 AC 15 ms
8,268 KB
testcase_02 AC 14 ms
8,336 KB
testcase_03 AC 15 ms
8,328 KB
testcase_04 AC 16 ms
8,320 KB
testcase_05 AC 16 ms
8,308 KB
testcase_06 AC 15 ms
8,304 KB
testcase_07 AC 15 ms
8,188 KB
testcase_08 AC 18 ms
8,548 KB
testcase_09 AC 16 ms
8,256 KB
testcase_10 AC 19 ms
8,696 KB
testcase_11 AC 33 ms
8,604 KB
testcase_12 AC 41 ms
9,144 KB
testcase_13 AC 38 ms
9,020 KB
testcase_14 AC 13 ms
8,200 KB
testcase_15 AC 14 ms
8,188 KB
testcase_16 AC 15 ms
8,188 KB
testcase_17 AC 15 ms
8,224 KB
testcase_18 AC 16 ms
8,324 KB
testcase_19 AC 15 ms
8,268 KB
testcase_20 AC 18 ms
8,300 KB
testcase_21 AC 16 ms
8,216 KB
testcase_22 AC 15 ms
8,148 KB
testcase_23 AC 65 ms
8,628 KB
testcase_24 AC 64 ms
8,468 KB
testcase_25 AC 21 ms
8,300 KB
testcase_26 AC 17 ms
8,200 KB
testcase_27 AC 51 ms
8,636 KB
testcase_28 AC 15 ms
8,272 KB
testcase_29 AC 21 ms
8,400 KB
testcase_30 AC 16 ms
8,236 KB
testcase_31 AC 21 ms
8,328 KB
testcase_32 AC 23 ms
8,512 KB
testcase_33 AC 19 ms
8,160 KB
testcase_34 AC 49 ms
8,656 KB
testcase_35 AC 17 ms
8,276 KB
testcase_36 AC 17 ms
8,192 KB
testcase_37 AC 17 ms
8,216 KB
testcase_38 AC 15 ms
8,260 KB
testcase_39 AC 15 ms
8,164 KB
testcase_40 AC 16 ms
8,228 KB
testcase_41 AC 14 ms
8,332 KB
testcase_42 AC 14 ms
8,392 KB
testcase_43 AC 16 ms
8,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(N, C, V, S, T, Y, M):
    S = [s - 1 for s in S]
    T = [t - 1 for t in T]

    DP = [{} for n in range(N)]
    # DP[s][c] は、街i に残コスト c でたどり着いたときにかかった時間

    R = [[] for n in range(N)]
    for v in range(V):
        R[S[v]].append(v)

    DP[0][C] = 0

    for s in range(N):
        dpi = DP[s]
        for c in dpi:
            for v in R[s]:
                t, y, m = T[v], Y[v], M[v]
                if c < y:
                    continue
                dpt = DP[t]
                if c - y in dpt:
                    dpt[c - y] = min(dpt[c - y], dpi[c] + m)
                else:
                    dpt[c - y] = dpi[c] + m

    if len(DP[-1]) == 0:
        return -1
    return min(DP[-1].values())


def main():
    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()))

    print(solve(N, C, V, S, T, Y, M))


if __name__ == '__main__':
    main()
0