結果
| 問題 | No.2289 順列ソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-14 15:54:08 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 2,000 ms |
| + 351µs | |
| コード長 | 696 bytes |
| 記録 | |
| コンパイル時間 | 1,939 ms |
| コンパイル使用メモリ | 336,640 KB |
| 実行使用メモリ | 9,868 KB |
| 最終ジャッジ日時 | 2026-09-22 13:19:37 |
| 合計ジャッジ時間 | 4,103 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) (void(0))
#else
#include "algo/debug.h"
#endif
void solve() {
int N; cin >> N;
vector<int> A(N);
for(int i = 0; i < N; i++) cin >> A[i], A[i]--;
vector<bool> seen(N);
int ans = 0;
for(int i = 0; i < N; i++) {
int size = 0;
int cur = i;
do {
size += 1;
seen[cur] = true;
cur = A[cur];
}while(!seen[cur]);
ans += size - 1;
}
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1;
// std::cin >> tt;
while(tt--) {
solve();
}
}