結果

問題 No.1 道のショートカット
ユーザー nebukuro09
提出日時 2016-09-02 13:23:34
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 695 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 76,800 KB
実行使用メモリ 79,488 KB
最終ジャッジ日時 2024-07-20 16:26:52
合計ジャッジ時間 6,935 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

N, C, V = input(), input(), input()
S = map(int, raw_input().split())
T = map(int, raw_input().split())
Y = map(int, raw_input().split())
M = map(int, raw_input().split())

rinsetsu = [[] for i in xrange(N)]
for i in xrange(V):
    rinsetsu[S[i]-1].append((T[i]-1, Y[i], M[i]))

mem = {}
def rec(node, cost):
    if (node, cost) in mem:
        return mem[(node, cost)]

    if cost < 0:
        return float('inf')
    
    if node == N-1:
        return 0

    minv = float('inf')
    for t, y, m in rinsetsu[node]:
        a = rec(t, cost-y) + m
        if a < minv:
            minv = a

    mem[(node, cost)] = minv
    return minv

ans = rec(0, C)
print -1 if ans == float('inf') else ans
0