結果

問題 No.1 道のショートカット
ユーザー warashiwarashi
提出日時 2015-02-09 11:38:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 965 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 9,948 KB
最終ジャッジ日時 2023-09-27 21:38:24
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,516 KB
testcase_01 AC 18 ms
8,640 KB
testcase_02 AC 17 ms
8,724 KB
testcase_03 AC 18 ms
8,564 KB
testcase_04 AC 17 ms
8,636 KB
testcase_05 AC 17 ms
8,612 KB
testcase_06 AC 17 ms
8,728 KB
testcase_07 AC 16 ms
8,592 KB
testcase_08 AC 20 ms
8,964 KB
testcase_09 AC 18 ms
8,696 KB
testcase_10 AC 21 ms
8,860 KB
testcase_11 AC 26 ms
9,024 KB
testcase_12 AC 37 ms
9,492 KB
testcase_13 AC 35 ms
9,556 KB
testcase_14 AC 16 ms
8,616 KB
testcase_15 AC 16 ms
8,640 KB
testcase_16 AC 16 ms
8,592 KB
testcase_17 AC 16 ms
8,684 KB
testcase_18 AC 17 ms
8,732 KB
testcase_19 AC 15 ms
8,712 KB
testcase_20 AC 17 ms
8,692 KB
testcase_21 AC 17 ms
8,676 KB
testcase_22 AC 16 ms
8,616 KB
testcase_23 AC 35 ms
9,464 KB
testcase_24 AC 34 ms
9,548 KB
testcase_25 AC 20 ms
8,832 KB
testcase_26 AC 17 ms
8,712 KB
testcase_27 AC 31 ms
9,228 KB
testcase_28 AC 15 ms
8,680 KB
testcase_29 AC 21 ms
8,780 KB
testcase_30 AC 16 ms
8,588 KB
testcase_31 AC 19 ms
8,876 KB
testcase_32 AC 22 ms
9,236 KB
testcase_33 AC 19 ms
8,912 KB
testcase_34 AC 37 ms
9,948 KB
testcase_35 AC 17 ms
8,768 KB
testcase_36 AC 18 ms
8,732 KB
testcase_37 AC 17 ms
8,672 KB
testcase_38 AC 16 ms
8,556 KB
testcase_39 AC 16 ms
8,544 KB
testcase_40 AC 17 ms
8,616 KB
testcase_41 AC 17 ms
8,568 KB
testcase_42 AC 16 ms
8,644 KB
testcase_43 AC 15 ms
8,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
from collections import defaultdict


def memoize(f):
    table = {}

    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func

N = int(input())
C = int(input())
V = int(input())
S = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
M = [int(x) for x in input().split()]
e = defaultdict(list)
for s, t, y, m in zip(S, T, Y, M):
    e[t].append((s, y, m))


@memoize
def path(now):
    if now == 1:
        return {0: 0}
    tmp = defaultdict(list)
    for s, y, m in e[now]:
        for cost, time in path(s).items():
            cost += y
            time += m
            if cost <= C:
                tmp[cost].append(time)
    ret = {}
    for cost, times in tmp.items():
        ret[cost] = min(times)
    return ret

walks = path(N).values()
if len(walks) == 0:
    print(-1)
else:
    print(min(walks))
0