結果

問題 No.1 道のショートカット
ユーザー brthyyjpbrthyyjp
提出日時 2021-10-30 02:42:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 1,087 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,944 KB
実行使用メモリ 87,416 KB
最終ジャッジ日時 2024-04-16 16:07:46
合計ジャッジ時間 5,079 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,992 KB
testcase_01 AC 41 ms
52,992 KB
testcase_02 AC 42 ms
53,120 KB
testcase_03 AC 40 ms
52,736 KB
testcase_04 AC 39 ms
53,120 KB
testcase_05 AC 40 ms
52,864 KB
testcase_06 AC 40 ms
52,480 KB
testcase_07 AC 44 ms
52,864 KB
testcase_08 AC 137 ms
84,608 KB
testcase_09 AC 69 ms
73,856 KB
testcase_10 AC 106 ms
78,848 KB
testcase_11 AC 122 ms
81,024 KB
testcase_12 AC 197 ms
87,416 KB
testcase_13 AC 178 ms
86,936 KB
testcase_14 AC 53 ms
64,000 KB
testcase_15 AC 45 ms
59,904 KB
testcase_16 AC 58 ms
66,944 KB
testcase_17 AC 49 ms
60,672 KB
testcase_18 AC 54 ms
63,872 KB
testcase_19 AC 53 ms
64,640 KB
testcase_20 AC 101 ms
78,340 KB
testcase_21 AC 66 ms
70,912 KB
testcase_22 AC 55 ms
64,384 KB
testcase_23 AC 138 ms
83,584 KB
testcase_24 AC 145 ms
85,888 KB
testcase_25 AC 116 ms
79,744 KB
testcase_26 AC 99 ms
78,440 KB
testcase_27 AC 142 ms
83,244 KB
testcase_28 AC 50 ms
62,208 KB
testcase_29 AC 85 ms
77,380 KB
testcase_30 AC 53 ms
63,488 KB
testcase_31 AC 62 ms
67,840 KB
testcase_32 AC 126 ms
82,356 KB
testcase_33 AC 100 ms
80,372 KB
testcase_34 AC 133 ms
82,560 KB
testcase_35 AC 49 ms
62,592 KB
testcase_36 AC 69 ms
71,168 KB
testcase_37 AC 52 ms
63,616 KB
testcase_38 AC 52 ms
62,848 KB
testcase_39 AC 57 ms
65,408 KB
testcase_40 AC 54 ms
63,744 KB
testcase_41 AC 48 ms
60,544 KB
testcase_42 AC 41 ms
53,120 KB
testcase_43 AC 45 ms
60,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
INF = 10**18
def dijkstra(s, edge):
    n = len(edge)
    dist = [INF]*n
    dist[s] = 0
    edgelist = []
    heapq.heappush(edgelist,(dist[s], s))
    while edgelist:
        minedge = heapq.heappop(edgelist)
        if dist[minedge[1]] < minedge[0]:
            continue
        v = minedge[1]
        for e in edge[v]:
            if dist[e[1]] > dist[v]+e[0]:
                dist[e[1]] = dist[v]+e[0]
                heapq.heappush(edgelist,(dist[e[1]], e[1]))
    return dist

n = int(input())
c = int(input())
a = int(input())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
Y = list(map(int, input().split()))
M = list(map(int, input().split()))

N = n*(c+1)
edge = [[] for i in range(N)]
for i in range(a):
    s, t, y, m = S[i], T[i], Y[i], M[i]
    s, t = s-1, t-1
    for j in range(c+1):
        if j+y <= c:
            edge[n*j+s].append((m, n*(j+y)+t))

dist = dijkstra(0, edge)
ans = INF
for i in range(N):
    cost, v = divmod(i, n)
    if v == n-1:
        ans = min(dist[i], ans)
if ans < INF:
    print(ans)
else:
    print(-1)
0