結果
問題 | No.2289 順列ソート |
ユーザー |
![]() |
提出日時 | 2023-05-05 21:21:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 466 bytes |
コンパイル時間 | 1,668 ms |
コンパイル使用メモリ | 170,764 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-23 05:44:53 |
合計ジャッジ時間 | 2,330 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){int N;cin >> N;vector<int> P(N);for (int i = 0; i < N; i++){cin >> P[i];P[i]--;}int ans = 0;vector<bool> used(N, false);for (int i = 0; i < N; i++){if (!used[i]){used[i] = true;int v = i;while (true){v = P[v];if (used[v]){break;}used[v] = true;ans++;}}}cout << ans << endl;}