結果

問題 No.1995 CHIKA Road
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-19 00:16:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,511 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 114,856 KB
最終ジャッジ日時 2023-09-17 05:10:18
合計ジャッジ時間 20,167 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,028 KB
testcase_01 AC 17 ms
8,120 KB
testcase_02 AC 17 ms
8,188 KB
testcase_03 AC 17 ms
8,004 KB
testcase_04 AC 17 ms
8,080 KB
testcase_05 AC 18 ms
8,128 KB
testcase_06 AC 78 ms
14,740 KB
testcase_07 AC 274 ms
29,392 KB
testcase_08 AC 18 ms
8,556 KB
testcase_09 AC 18 ms
8,332 KB
testcase_10 AC 372 ms
33,624 KB
testcase_11 AC 1,511 ms
114,856 KB
testcase_12 AC 827 ms
82,484 KB
testcase_13 AC 436 ms
41,688 KB
testcase_14 AC 477 ms
43,584 KB
testcase_15 AC 1,341 ms
107,060 KB
testcase_16 AC 126 ms
17,920 KB
testcase_17 AC 603 ms
49,668 KB
testcase_18 AC 1,082 ms
78,012 KB
testcase_19 AC 1,090 ms
77,996 KB
testcase_20 AC 542 ms
45,804 KB
testcase_21 AC 493 ms
43,092 KB
testcase_22 AC 1,017 ms
74,524 KB
testcase_23 AC 278 ms
30,092 KB
testcase_24 AC 866 ms
67,260 KB
testcase_25 AC 153 ms
21,284 KB
testcase_26 AC 334 ms
34,240 KB
testcase_27 AC 840 ms
65,808 KB
testcase_28 AC 498 ms
42,972 KB
testcase_29 AC 1,049 ms
75,984 KB
testcase_30 AC 144 ms
20,852 KB
testcase_31 AC 73 ms
13,976 KB
testcase_32 AC 200 ms
24,724 KB
testcase_33 AC 800 ms
65,036 KB
testcase_34 AC 81 ms
14,928 KB
testcase_35 AC 302 ms
31,792 KB
testcase_36 AC 365 ms
36,376 KB
testcase_37 AC 932 ms
71,680 KB
testcase_38 AC 655 ms
54,676 KB
testcase_39 AC 70 ms
13,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq as hq
import sys
input = sys.stdin.readline
INF = 10 ** 18

n, 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 -= 1
	st.add(a);	st.add(b)
	edge.append((a, b))
lis = sorted(st)
N = len(lis)

cnt = 0
for i in lis:
	h[i] = cnt
	cnt += 1
route = [[] 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] * N
	q = [(0, start)]
	while(q):
		d, v = hq.heappop(q)
		if(path[v] <= d):
			continue
		path[v] = d
		if(v == finish):
			break
		for nv, dist in route[v]:
			hq.heappush(q, (d + dist, nv))
	return path[finish]

ans = dijkstra(route, 0, N - 1)
print(ans)
0