結果

問題 No.1 道のショートカット
ユーザー warashiwarashi
提出日時 2015-02-08 18:47:52
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,453 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 86,664 KB
実行使用メモリ 845,300 KB
最終ジャッジ日時 2023-09-22 11:56:32
合計ジャッジ時間 6,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
72,276 KB
testcase_01 AC 105 ms
72,348 KB
testcase_02 AC 103 ms
72,392 KB
testcase_03 AC 103 ms
72,460 KB
testcase_04 AC 105 ms
72,124 KB
testcase_05 AC 106 ms
72,176 KB
testcase_06 AC 104 ms
72,180 KB
testcase_07 AC 104 ms
72,396 KB
testcase_08 AC 192 ms
81,888 KB
testcase_09 AC 162 ms
79,768 KB
testcase_10 AC 245 ms
92,000 KB
testcase_11 MLE -
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 #

#!/usr/bin/env python3
import functools
import itertools
import operator


def memoize(fn):
    table = {}

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

N = int(input())
C = int(input())
V = int(input())
S = [int(s) for s in input().split()]
T = [int(t) for t in input().split()]
Y = [int(y) for y in input().split()]
M = [int(m) for m in input().split()]

RODE = list(zip(S, T, Y, M))


@memoize
def path(town, yen):
    if town == 1:
        return [[1]]
    road = [path(s, yen - y)
            for s, t, y, m in RODE if t == town and yen >= y]
    if len(road) < 1:
        return [[-1]]
    return [p + [town] for p in functools.reduce(operator.add, road)]


@memoize
def roads(fr, to):
    return [(y, m) for s, t, y, m in RODE if s == fr and t == to]


def cost_and_meter(roads):
    cost = 0
    meter = 0
    for road in roads:
        cost += road[0]
        meter += road[1]
    return (cost, meter)


def min_cost_and_meter(path):
    road = []
    for i in range(1, len(path)):
        road.append(roads(path[i - 1], path[i]))
    ways = itertools.product(*road)
    c_m = [cost_and_meter(way) for way in ways]
    path = [m for y, m in c_m if y <= C]
    if len(path) == 0:
        return -1
    return min(path)

meters = [m for m in [min_cost_and_meter(p) for p in path(N, C)] if m > 0]
if len(meters) == 0:
    print(-1)
else:
    print(min(meters))
0