結果

問題 No.3650 Teleportation Cycles
コンテスト
ユーザー Rino-program
提出日時 2026-07-21 22:54:10
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 524 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 257 ms
コンパイル使用メモリ 96,112 KB
実行使用メモリ 116,480 KB
最終ジャッジ日時 2026-08-28 21:02:42
合計ジャッジ時間 5,093 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

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"""
    # 追加
    for idx in range(N): # N回
    	if S[idx] == 1:
    		S[idx] = 2

print(ans)
0