結果

問題 No.1995 CHIKA Road
ユーザー ああいいああいい
提出日時 2022-07-01 21:51:28
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 980 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 176,988 KB
最終ジャッジ日時 2023-08-17 09:24:07
合計ジャッジ時間 17,982 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,716 KB
testcase_01 AC 93 ms
71,764 KB
testcase_02 AC 91 ms
71,568 KB
testcase_03 AC 91 ms
71,432 KB
testcase_04 AC 92 ms
71,444 KB
testcase_05 AC 104 ms
76,656 KB
testcase_06 AC 215 ms
82,408 KB
testcase_07 AC 329 ms
97,948 KB
testcase_08 AC 115 ms
76,868 KB
testcase_09 AC 105 ms
76,620 KB
testcase_10 AC 350 ms
89,008 KB
testcase_11 AC 980 ms
176,988 KB
testcase_12 AC 426 ms
121,816 KB
testcase_13 AC 409 ms
108,516 KB
testcase_14 AC 425 ms
106,728 KB
testcase_15 AC 836 ms
145,176 KB
testcase_16 AC 238 ms
86,544 KB
testcase_17 AC 508 ms
119,480 KB
testcase_18 AC 727 ms
126,040 KB
testcase_19 AC 729 ms
125,800 KB
testcase_20 AC 481 ms
114,856 KB
testcase_21 AC 446 ms
110,620 KB
testcase_22 AC 700 ms
120,832 KB
testcase_23 AC 334 ms
98,444 KB
testcase_24 AC 634 ms
130,060 KB
testcase_25 AC 265 ms
88,260 KB
testcase_26 AC 393 ms
100,852 KB
testcase_27 AC 610 ms
128,784 KB
testcase_28 AC 443 ms
110,612 KB
testcase_29 AC 713 ms
123,744 KB
testcase_30 AC 274 ms
88,656 KB
testcase_31 AC 210 ms
81,796 KB
testcase_32 AC 288 ms
92,020 KB
testcase_33 AC 602 ms
128,404 KB
testcase_34 AC 230 ms
82,808 KB
testcase_35 AC 344 ms
100,864 KB
testcase_36 AC 399 ms
97,988 KB
testcase_37 AC 669 ms
126,928 KB
testcase_38 AC 528 ms
113,124 KB
testcase_39 AC 213 ms
81,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())

s = set()
from collections import defaultdict
G = defaultdict(list)
for _ in range(M):
    a,b = map(int,input().split())
    G[a].append((b,2 * b - 2 * a - 1))
    s.add(a)
    s.add(b)
s.add(1)
s.add(N)
l = sorted(s)
D = {v:i for i,v in enumerate(l)}

n = len(l)
for i in range(n - 1):
    G[l[i]].append((l[i+1],2 * (l[i+1] - l[i])))
                   
inf = 10 ** 10
dist = [inf] * n
dist[0] = 0
import heapq
q = [(0,1)]
while q:
    d,now = heapq.heappop(q)
    if dist[D[now]] < d:continue
    for v,c in G[now]:
        if dist[D[v]] > d + c:
            dist[D[v]] = d + c
            heapq.heappush(q,(d + c,v))
print(dist[-1])
0