結果

問題 No.3650 Teleportation Cycles
コンテスト
ユーザー Rino-program
提出日時 2026-07-21 12:26:59
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 116 ms / 2,000 ms
+ 477µs
コード長 415 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 289 ms
コンパイル使用メモリ 95,596 KB
実行使用メモリ 129,664 KB
最終ジャッジ日時 2026-08-28 20:59:31
合計ジャッジ時間 5,616 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
A = list(map(int, input().split()))

S = [0] * N

ans = 0
for i in range(N):
    now_idx = i
    now_li = []
    if not S[now_idx]:
        while not S[now_idx]:
            now_li.append(now_idx)
            S[now_idx] = 1
            now_idx = A[now_idx] - 1 # 1-indexed を 0-indexedに直す
        if S[now_idx] == 1:
            ans += 1
    for idx in now_li:
        S[idx] = 2

print(ans)
0