結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-09 11:38:52 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 5,000 ms |
| コード長 | 965 bytes |
| コンパイル時間 | 117 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 12,032 KB |
| 最終ジャッジ日時 | 2024-07-20 16:08:47 |
| 合計ジャッジ時間 | 2,615 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#!/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))