結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2015-02-09 11:36:12 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,004 bytes |
コンパイル時間 | 120 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-08 03:45:54 |
合計ジャッジ時間 | 2,799 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | RE * 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(e, max_cost, now): if now == 1: return {0: 0} tmp = defaultdict(list) for s, y, m in e[now]: for cost, time in path(e, max_cost, s).items(): cost += y time += m if cost <= max_cost: tmp[cost].append(time) ret = {} for cost, times in tmp.items(): ret[cost] = min(times) return ret walks = path(e, C, N).values() if len(walks) == 0: print(-1) else: print(min(walks))