結果
問題 | No.1868 Teleporting Cyanmond |
ユーザー |
![]() |
提出日時 | 2022-03-11 21:24:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 460 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 98,176 KB |
最終ジャッジ日時 | 2024-09-16 01:23:57 |
合計ジャッジ時間 | 3,421 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
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])