結果

問題 No.1995 CHIKA Road
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-18 13:53:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 805 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 11,100 KB
実行使用メモリ 114,836 KB
最終ジャッジ日時 2023-09-17 05:07:42
合計ジャッジ時間 16,655 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,056 KB
testcase_01 AC 15 ms
8,184 KB
testcase_02 AC 16 ms
8,064 KB
testcase_03 AC 14 ms
8,124 KB
testcase_04 AC 15 ms
8,056 KB
testcase_05 WA -
testcase_06 AC 65 ms
14,536 KB
testcase_07 AC 230 ms
29,556 KB
testcase_08 AC 15 ms
8,320 KB
testcase_09 AC 15 ms
8,516 KB
testcase_10 AC 307 ms
33,652 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 106 ms
17,936 KB
testcase_17 AC 498 ms
49,704 KB
testcase_18 AC 911 ms
77,796 KB
testcase_19 AC 899 ms
77,940 KB
testcase_20 AC 445 ms
45,748 KB
testcase_21 AC 402 ms
42,888 KB
testcase_22 AC 852 ms
74,652 KB
testcase_23 AC 241 ms
30,052 KB
testcase_24 AC 728 ms
67,276 KB
testcase_25 AC 138 ms
21,308 KB
testcase_26 AC 269 ms
34,244 KB
testcase_27 AC 646 ms
66,008 KB
testcase_28 AC 394 ms
42,880 KB
testcase_29 AC 839 ms
75,920 KB
testcase_30 AC 124 ms
21,092 KB
testcase_31 AC 65 ms
13,992 KB
testcase_32 AC 166 ms
24,800 KB
testcase_33 AC 676 ms
65,200 KB
testcase_34 AC 68 ms
14,860 KB
testcase_35 AC 256 ms
31,664 KB
testcase_36 AC 304 ms
36,140 KB
testcase_37 AC 783 ms
71,592 KB
testcase_38 AC 553 ms
54,932 KB
testcase_39 AC 59 ms
13,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n, m = map(int,input().split())
h = {};	st = set([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