結果
| 問題 |
No.3217 Shiki no Shiki
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-06 17:06:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 355 bytes |
| コンパイル時間 | 298 ms |
| コンパイル使用メモリ | 82,792 KB |
| 実行使用メモリ | 99,076 KB |
| 最終ジャッジ日時 | 2025-08-06 17:06:47 |
| 合計ジャッジ時間 | 3,402 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 WA * 21 |
ソースコード
from collections import defaultdict
N = int(input())
P = list(map(int, input().split()))
shikigami = defaultdict(lambda: -1)
ans = 0
for i in range(N):
p = P[i]-1
if p == -1:
cnt = 0
c = i
while shikigami[c] != -1:
cnt += 1
c = shikigami[c]
ans += cnt >= 2
shikigami[p] = i
print(ans)