結果
| 問題 |
No.2289 順列ソート
|
| コンテスト | |
| ユーザー |
hiro71687k
|
| 提出日時 | 2023-05-10 16:57:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 652 bytes |
| コンパイル時間 | 3,457 ms |
| コンパイル使用メモリ | 250,000 KB |
| 最終ジャッジ日時 | 2025-02-12 21:12:00 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=14449999999999999;
ll mod=998244353;
int main(){
ll n;
cin >> n;
vector<ll>p(n);
vector<ll>c(n);
for (ll i = 0; i < n; i++)
{
cin >> p[i];
p[i]--;
c[p[i]]=i;
}
ll ans=0;
for (ll i = 0; i < n; i++)
{
if (c[i]!=i)
{
ans+=1;
ll x=i,y=c[i],a=p[i],b=p[c[i]];
p[y]=p[i];
p[i]=i;
c[a]=y;
c[i]=i;
}
}
cout << ans << endl;
}
hiro71687k