結果

問題 No.1 道のショートカット
ユーザー DialBirdDialBird
提出日時 2019-07-18 21:29:31
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 859 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 8,616 KB
最終ジャッジ日時 2023-09-27 22:20:25
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,020 KB
testcase_01 AC 14 ms
8,100 KB
testcase_02 AC 14 ms
8,136 KB
testcase_03 AC 14 ms
8,020 KB
testcase_04 AC 13 ms
8,008 KB
testcase_05 AC 13 ms
8,020 KB
testcase_06 AC 14 ms
8,052 KB
testcase_07 AC 14 ms
8,016 KB
testcase_08 AC 15 ms
8,564 KB
testcase_09 AC 14 ms
8,020 KB
testcase_10 AC 14 ms
8,064 KB
testcase_11 AC 14 ms
8,528 KB
testcase_12 AC 15 ms
8,604 KB
testcase_13 AC 16 ms
8,604 KB
testcase_14 AC 13 ms
8,072 KB
testcase_15 AC 13 ms
8,080 KB
testcase_16 AC 14 ms
8,064 KB
testcase_17 AC 13 ms
8,012 KB
testcase_18 AC 14 ms
8,204 KB
testcase_19 AC 13 ms
8,368 KB
testcase_20 AC 14 ms
8,156 KB
testcase_21 AC 14 ms
8,016 KB
testcase_22 AC 14 ms
8,344 KB
testcase_23 AC 16 ms
8,608 KB
testcase_24 AC 14 ms
8,008 KB
testcase_25 AC 14 ms
8,160 KB
testcase_26 AC 13 ms
8,080 KB
testcase_27 AC 15 ms
8,616 KB
testcase_28 AC 14 ms
8,072 KB
testcase_29 AC 16 ms
8,564 KB
testcase_30 AC 13 ms
8,064 KB
testcase_31 AC 14 ms
8,100 KB
testcase_32 AC 15 ms
8,052 KB
testcase_33 AC 14 ms
8,076 KB
testcase_34 AC 15 ms
8,444 KB
testcase_35 AC 15 ms
8,468 KB
testcase_36 AC 14 ms
8,412 KB
testcase_37 AC 14 ms
8,012 KB
testcase_38 AC 13 ms
8,236 KB
testcase_39 AC 14 ms
7,988 KB
testcase_40 AC 13 ms
8,024 KB
testcase_41 AC 14 ms
8,040 KB
testcase_42 AC 13 ms
8,140 KB
testcase_43 AC 13 ms
7,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush


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

    ways_from = {}
    ways_from = [set() for i in range(N+1)]
    for i in range(V):
        ways_from[S[i]].add((T[i], Y[i], M[i]))

    # time, pos, cost
    heap = [(0, 1, 0)]
    res = -1

    while heap:
        time, pos, cost = heappop(heap)

        if pos == N:
            res = time
            break

        for next_pos, way_cost, way_time in ways_from[pos]:
            next_cost = cost + way_cost
            if C < next_cost:
                continue
            heappush(heap, (time + way_time, next_pos, next_cost))

    return res


print(main())
0