結果

問題 No.1 道のショートカット
ユーザー DialBirdDialBird
提出日時 2019-07-16 23:39:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,094 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 8,804 KB
最終ジャッジ日時 2023-09-22 13:33:02
合計ジャッジ時間 2,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,004 KB
testcase_01 AC 16 ms
8,008 KB
testcase_02 AC 18 ms
8,056 KB
testcase_03 AC 18 ms
8,088 KB
testcase_04 AC 17 ms
8,156 KB
testcase_05 AC 16 ms
8,000 KB
testcase_06 AC 16 ms
8,140 KB
testcase_07 AC 17 ms
8,144 KB
testcase_08 AC 18 ms
8,488 KB
testcase_09 AC 17 ms
8,100 KB
testcase_10 AC 19 ms
8,436 KB
testcase_11 AC 18 ms
8,508 KB
testcase_12 AC 19 ms
8,500 KB
testcase_13 AC 18 ms
8,440 KB
testcase_14 AC 17 ms
8,264 KB
testcase_15 RE -
testcase_16 AC 17 ms
8,056 KB
testcase_17 AC 16 ms
8,156 KB
testcase_18 AC 16 ms
8,288 KB
testcase_19 AC 16 ms
8,176 KB
testcase_20 AC 17 ms
8,092 KB
testcase_21 AC 19 ms
8,280 KB
testcase_22 AC 17 ms
8,272 KB
testcase_23 AC 19 ms
8,804 KB
testcase_24 AC 18 ms
8,588 KB
testcase_25 AC 17 ms
8,080 KB
testcase_26 AC 17 ms
8,004 KB
testcase_27 AC 18 ms
8,544 KB
testcase_28 RE -
testcase_29 AC 18 ms
8,480 KB
testcase_30 AC 18 ms
8,064 KB
testcase_31 AC 18 ms
8,496 KB
testcase_32 AC 18 ms
8,560 KB
testcase_33 AC 18 ms
8,040 KB
testcase_34 AC 18 ms
8,496 KB
testcase_35 AC 18 ms
8,440 KB
testcase_36 AC 17 ms
8,448 KB
testcase_37 AC 18 ms
8,488 KB
testcase_38 AC 16 ms
8,268 KB
testcase_39 AC 16 ms
8,284 KB
testcase_40 AC 16 ms
8,028 KB
testcase_41 AC 16 ms
8,244 KB
testcase_42 AC 16 ms
8,036 KB
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = {}
    for i in range(V):
        if ways_from.get(S[i]):
            ways_from[S[i]].append({'next': T[i], 'cost': Y[i], 'min': M[i]})
        else:
            ways_from[S[i]] = [{'next': T[i], 'cost': Y[i], 'min': M[i]}]

    # time, pos, cost
    candidates = [(0, 1, 0)]
    res = None

    while candidates:
        candidate = heappop(candidates)

        if candidate[1] == N:
            res = candidate[0]
            break

        if not ways_from[candidate[1]]:
            continue

        for way in ways_from[candidate[1]]:
            next_cost = candidate[2] + way['cost']
            if C < next_cost:
                continue
            heappush(
                candidates, (candidate[0] + way['min'], way['next'], next_cost))
    return res or -1


print(main())
0