結果

問題 No.1995 CHIKA Road
ユーザー titan23titan23
提出日時 2022-07-01 23:21:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 931 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 129,936 KB
最終ジャッジ日時 2023-08-17 11:06:50
合計ジャッジ時間 15,683 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,812 KB
testcase_01 AC 90 ms
71,792 KB
testcase_02 AC 92 ms
71,296 KB
testcase_03 AC 91 ms
71,620 KB
testcase_04 AC 92 ms
71,736 KB
testcase_05 WA -
testcase_06 AC 217 ms
82,628 KB
testcase_07 AC 308 ms
92,548 KB
testcase_08 AC 114 ms
76,812 KB
testcase_09 AC 110 ms
76,520 KB
testcase_10 AC 371 ms
98,000 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 227 ms
84,852 KB
testcase_17 AC 489 ms
108,712 KB
testcase_18 AC 715 ms
129,936 KB
testcase_19 AC 727 ms
129,512 KB
testcase_20 AC 454 ms
106,508 KB
testcase_21 AC 422 ms
103,724 KB
testcase_22 AC 654 ms
125,632 KB
testcase_23 AC 305 ms
92,408 KB
testcase_24 AC 604 ms
120,880 KB
testcase_25 AC 250 ms
86,528 KB
testcase_26 AC 345 ms
96,152 KB
testcase_27 AC 586 ms
119,032 KB
testcase_28 AC 422 ms
104,360 KB
testcase_29 AC 685 ms
128,836 KB
testcase_30 AC 245 ms
86,168 KB
testcase_31 AC 209 ms
81,908 KB
testcase_32 AC 275 ms
88,564 KB
testcase_33 AC 588 ms
118,692 KB
testcase_34 AC 201 ms
82,584 KB
testcase_35 AC 333 ms
94,028 KB
testcase_36 AC 374 ms
98,580 KB
testcase_37 AC 655 ms
125,116 KB
testcase_38 AC 509 ms
110,436 KB
testcase_39 AC 199 ms
81,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict, deque
from heapq import heapify, heappush, heappop
input = lambda: sys.stdin.readline().rstrip()
inf = float('inf')

def dijkstra(G: list, s: int) -> list:
  "Return dist from s. / O(|E|log|V|)"
  dist = defaultdict(lambda: inf)
  dist[s] = 0
  hq = [(0, s)]
  while hq:
    d, v = heappop(hq)
    if dist[v] < d:
      continue
    for x,c in G[v]:
      if dist[x] > d + c:
        dist[x] = d + c
        heappush(hq, (d+c, x))
  return dist

#  -----------------------  #

n, m = map(int, input().split())
G = defaultdict(list)
E = []
mx = 0

for _ in range(m):
  a, b = map(int, input().split())
  G[a-1].append((b-1, 2*b-2*a-1))
  E.append(a-1)
  E.append(b-1)
  mx = max(mx, b-1)

G[mx].append((n-1, (n-1 - mx)*2))

E.sort()

for i in range(len(E)-1):
  now, nxt = E[i], E[i+1]
  dist = (E[i+1] - E[i]) * 2
  G[now].append((nxt, dist))

dist = dijkstra(G, 0)
print(dist[n-1])
0