結果

問題 No.1 道のショートカット
ユーザー sue_charosue_charo
提出日時 2017-04-21 18:13:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,524 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 14,780 KB
最終ジャッジ日時 2023-09-22 13:07:30
合計ジャッジ時間 7,369 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,992 KB
testcase_01 AC 30 ms
10,032 KB
testcase_02 AC 30 ms
9,888 KB
testcase_03 AC 30 ms
9,944 KB
testcase_04 AC 30 ms
9,944 KB
testcase_05 AC 29 ms
10,020 KB
testcase_06 AC 30 ms
10,004 KB
testcase_07 AC 29 ms
9,952 KB
testcase_08 AC 48 ms
10,476 KB
testcase_09 AC 33 ms
10,124 KB
testcase_10 AC 74 ms
10,384 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, C, V, S, T, Y, M):
    graph = [[] for __ in range(N + 1)]
    for s, t, y, m in zip(S, T, Y, M):
        graph[s].append((t, y, m))
    dp = collections.defaultdict(lambda: INF)
    dp[(1, C)] = 0

    city_queue = collections.deque([(1, C)])
    while city_queue:
        city_money = city_queue.pop()
        l_next = graph[city_money[0]]
        if len(l_next) == 0:
            continue

        for next in l_next:
            now_time = dp[(city_money)]
            next_time = now_time + next[2]
            next_money = city_money[1] - next[1]
            next_city = next[0]

            if next_money < 0:
                continue

            dp[(next_city, next_money)] = min(next_time, dp[(next_city, next_money)])

            collections.deque.append(city_queue, (next_city, next_money))

    ans = INF
    for i in range(C + 1):
        ans = min(ans, dp[(N, i)])

    if ans == INF:
        ans = -1

    return ans


def main():
    N = II()
    C = II()
    V = II()
    S = [0] + ILI()
    T = [0] + ILI()
    Y = [0] + ILI()
    M = [0] + ILI()
    print(solve(N, C, V, S, T, Y, M))
 
 
if __name__ == "__main__":
    main()
0