結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2020-09-05 18:13:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 156 ms / 5,000 ms |
コード長 | 963 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 86,528 KB |
最終ジャッジ日時 | 2024-07-20 16:51:57 |
合計ジャッジ時間 | 4,800 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
from heapq import heapify, heappush as hpush, heappop as hpop N, C, V = int(input()), int(input()), int(input()) S = [int(a)-1 for a in input().split()] T = [int(a)-1 for a in input().split()] Y = [int(a) for a in input().split()] M = [int(a) for a in input().split()] X = [[] for _ in range(N * (C + 1))] # i * N + j: i 円使って頂点jにいる状態 for s, t, y, m in zip(S, T, Y, M): for i in range(y, C + 1): X[(i-y)*N+s].append((i*N+t, m)) def dijkstra(n, E, i0=0): kk = 18 mm = (1 << kk) - 1 h = [i0] D = [1 << 30] * n done = [0] * n D[i0] = 0 while h: x = hpop(h) d, i = x >> kk, x & mm done[i] = 1 for j, w in E[i]: nd = d + w if D[j] < 0 or D[j] > nd: if done[j] == 0: hpush(h, (nd << kk) + j) D[j] = nd return (min(D[N-1::N]) + 1) % (2 ** 30 + 1) - 1 print(dijkstra(N * (C + 1), X))