結果
問題 | No.1995 CHIKA Road |
ユーザー |
![]() |
提出日時 | 2022-02-19 00:16:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,613 ms / 2,000 ms |
コード長 | 808 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 117,484 KB |
最終ジャッジ日時 | 2024-07-04 02:36:24 |
合計ジャッジ時間 | 20,830 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
import heapq as hqimport sysinput = sys.stdin.readlineINF = 10 ** 18n, m = map(int,input().split())h = {}; st = set([0, n - 1])edge = []for _ in [0] * m:a, b = map(int,input().split())a -= 1; b -= 1st.add(a); st.add(b)edge.append((a, b))lis = sorted(st)N = len(lis)cnt = 0for i in lis:h[i] = cntcnt += 1route = [[] for _ in [0] * N]for a, b in edge:route[h[a]].append((h[b], 2 * b - 2 * a - 1))for i in range(N - 1):route[i].append((i + 1, 2 * (lis[i + 1] - lis[i])))def dijkstra(route, start, finish):path = [INF] * Nq = [(0, start)]while(q):d, v = hq.heappop(q)if(path[v] <= d):continuepath[v] = dif(v == finish):breakfor nv, dist in route[v]:hq.heappush(q, (d + dist, nv))return path[finish]ans = dijkstra(route, 0, N - 1)print(ans)