結果

問題 No.1868 Teleporting Cyanmond
ユーザー roarisroaris
提出日時 2022-03-20 20:50:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 96,896 KB
最終ジャッジ日時 2024-04-16 14:08:39
合計ジャッジ時間 3,666 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,760 KB
testcase_01 AC 41 ms
53,760 KB
testcase_02 AC 42 ms
53,760 KB
testcase_03 AC 105 ms
95,616 KB
testcase_04 AC 87 ms
92,032 KB
testcase_05 AC 59 ms
66,432 KB
testcase_06 AC 60 ms
71,040 KB
testcase_07 AC 85 ms
87,888 KB
testcase_08 AC 64 ms
75,904 KB
testcase_09 AC 85 ms
86,272 KB
testcase_10 AC 118 ms
94,208 KB
testcase_11 AC 53 ms
64,512 KB
testcase_12 AC 66 ms
74,880 KB
testcase_13 AC 88 ms
88,064 KB
testcase_14 AC 104 ms
95,412 KB
testcase_15 AC 95 ms
92,032 KB
testcase_16 AC 58 ms
69,120 KB
testcase_17 AC 61 ms
73,600 KB
testcase_18 AC 105 ms
96,640 KB
testcase_19 AC 108 ms
96,640 KB
testcase_20 AC 105 ms
96,896 KB
testcase_21 AC 105 ms
96,896 KB
testcase_22 AC 106 ms
96,768 KB
testcase_23 AC 103 ms
96,640 KB
testcase_24 AC 102 ms
96,804 KB
testcase_25 AC 102 ms
96,868 KB
testcase_26 AC 102 ms
96,640 KB
testcase_27 AC 102 ms
96,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N = int(input())
R = list(map(int, input().split()))
G = [[] for _ in range(N)]

for i in range(N-1):
    G[i].append((R[i]-1, 1))
    
for i in range(1, N):
    G[i].append((i-1, 0))

q = deque([0])
dist = [10**18]*N
dist[0] = 0

while q:
    v = q.popleft()
    
    for nv, w in G[v]:
        if dist[nv]>dist[v]+w:
            dist[nv] = dist[v]+w
        
            if w==0:
                q.appendleft(nv)
            else:
                q.append(nv)

print(dist[-1])
0