結果

問題 No.1868 Teleporting Cyanmond
ユーザー wolgnikwolgnik
提出日時 2022-03-11 21:24:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 460 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 97,860 KB
最終ジャッジ日時 2023-10-14 06:06:46
合計ジャッジ時間 5,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,444 KB
testcase_01 AC 96 ms
71,664 KB
testcase_02 AC 96 ms
71,904 KB
testcase_03 AC 167 ms
96,036 KB
testcase_04 AC 141 ms
92,572 KB
testcase_05 AC 111 ms
78,508 KB
testcase_06 AC 122 ms
80,204 KB
testcase_07 AC 144 ms
89,536 KB
testcase_08 AC 132 ms
85,820 KB
testcase_09 AC 137 ms
88,168 KB
testcase_10 AC 168 ms
95,284 KB
testcase_11 AC 111 ms
78,532 KB
testcase_12 AC 123 ms
82,172 KB
testcase_13 AC 138 ms
89,768 KB
testcase_14 AC 162 ms
96,404 KB
testcase_15 AC 145 ms
92,528 KB
testcase_16 AC 117 ms
79,748 KB
testcase_17 AC 118 ms
81,848 KB
testcase_18 AC 166 ms
97,744 KB
testcase_19 AC 165 ms
97,620 KB
testcase_20 AC 166 ms
97,556 KB
testcase_21 AC 167 ms
97,840 KB
testcase_22 AC 172 ms
97,860 KB
testcase_23 AC 168 ms
97,548 KB
testcase_24 AC 163 ms
97,548 KB
testcase_25 AC 166 ms
97,588 KB
testcase_26 AC 165 ms
97,588 KB
testcase_27 AC 162 ms
97,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))

e = [[] for _ in range(N)]
for x in range(N - 1): e[x + 1].append((x, 0))
for i in range(N - 1): e[i].append((a[i] - 1, 1))

from collections import deque as dq

Q = dq([0])
dp = [N + 1] * N
dp[0] = 0
while len(Q):
  x = Q.popleft()
  for y, c in e[x]:
    if dp[y] > dp[x] + c:
      dp[y] = dp[x] + c
      if c: Q.append(y)
      else: Q.appendleft(y)
print(dp[-1])
0