結果
問題 | No.2289 順列ソート |
ユーザー |
![]() |
提出日時 | 2025-03-20 18:44:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 438 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 53,960 KB |
最終ジャッジ日時 | 2025-03-20 18:44:17 |
合計ジャッジ時間 | 1,785 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
n = int(input())p = list(map(int, input().split()))visited = [False] * ntotal = 0for i in range(n):if not visited[i]:if p[i] == i + 1:visited[i] = Truecontinuecycle_length = 0current = iwhile not visited[current]:visited[current] = Truecycle_length += 1current = p[current] - 1total += (cycle_length - 1)print(total)