結果
| 問題 | No.2289 順列ソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-26 04:39:42 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| + 793µs | |
| コード長 | 405 bytes |
| 記録 | |
| コンパイル時間 | 3,352 ms |
| コンパイル使用メモリ | 174,012 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-26 04:40:04 |
| 合計ジャッジ時間 | 4,753 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(void){
int n; cin >> n;
vector<int> p(n), seen(n);
for(auto&x:p) cin >> x, x--;
int ans=0;
for(int i=0; i<n; i++){
if(seen[i]) continue;
int c=0, now=i;
while(!seen[now]){
seen[now]=1, c++;
now=p[now];
}
ans+=c-1;
}
cout << ans << endl;
return 0;
}