結果

問題 No.1868 Teleporting Cyanmond
ユーザー roarisroaris
提出日時 2022-03-20 20:47:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 543 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 97,248 KB
最終ジャッジ日時 2024-04-16 14:05:38
合計ジャッジ時間 4,078 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,016 KB
testcase_01 AC 41 ms
53,756 KB
testcase_02 AC 41 ms
53,760 KB
testcase_03 AC 109 ms
95,616 KB
testcase_04 AC 86 ms
92,160 KB
testcase_05 AC 55 ms
66,560 KB
testcase_06 AC 60 ms
70,912 KB
testcase_07 AC 87 ms
88,192 KB
testcase_08 AC 65 ms
75,776 KB
testcase_09 AC 82 ms
86,528 KB
testcase_10 AC 111 ms
94,336 KB
testcase_11 AC 55 ms
65,024 KB
testcase_12 AC 63 ms
74,240 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = [-1]*N
dist[0] = 0

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

print(dist[-1])
0