結果

問題 No.1868 Teleporting Cyanmond
ユーザー qibqib
提出日時 2023-03-13 03:20:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 522 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 81,728 KB
実行使用メモリ 97,744 KB
最終ジャッジ日時 2023-10-18 10:52:06
合計ジャッジ時間 7,064 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,492 KB
testcase_01 AC 41 ms
53,492 KB
testcase_02 AC 41 ms
53,492 KB
testcase_03 AC 231 ms
96,444 KB
testcase_04 AC 145 ms
92,552 KB
testcase_05 AC 111 ms
76,820 KB
testcase_06 AC 134 ms
79,416 KB
testcase_07 AC 175 ms
87,848 KB
testcase_08 AC 158 ms
82,440 KB
testcase_09 AC 171 ms
85,968 KB
testcase_10 AC 240 ms
95,056 KB
testcase_11 AC 101 ms
76,488 KB
testcase_12 AC 159 ms
81,284 KB
testcase_13 AC 178 ms
87,984 KB
testcase_14 AC 234 ms
96,264 KB
testcase_15 AC 195 ms
92,580 KB
testcase_16 AC 143 ms
78,736 KB
testcase_17 AC 152 ms
80,972 KB
testcase_18 AC 278 ms
97,744 KB
testcase_19 AC 226 ms
97,744 KB
testcase_20 AC 220 ms
97,744 KB
testcase_21 AC 250 ms
97,744 KB
testcase_22 AC 291 ms
97,744 KB
testcase_23 AC 166 ms
97,744 KB
testcase_24 AC 163 ms
97,744 KB
testcase_25 AC 164 ms
97,744 KB
testcase_26 AC 160 ms
97,744 KB
testcase_27 AC 163 ms
97,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

INF = 1 << 60

n = int(input())
r = list(map(int, input().split()))
g = [[] for _ in range(n)]
for u in range(n - 1):
  g[u].append((r[u] - 1, 1))

for u in range(n - 1):
  g[u + 1].append((u, 0))

src = 0
dist = [INF for _ in range(n)]
dist[src] = 0
hp = [(0, src)]
while len(hp) > 0:
  cd, cur = heapq.heappop(hp)
  if cd > dist[cur]:
    continue
  for nxt, cost in g[cur]:
    if dist[nxt] > dist[cur] + cost:
      dist[nxt] = dist[cur] + cost
      heapq.heappush(hp, (dist[nxt], nxt))

print(dist[-1])
0