結果
問題 |
No.2289 順列ソート
|
ユーザー |
![]() |
提出日時 | 2025-10-04 16:20:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 398 bytes |
コンパイル時間 | 1,630 ms |
コンパイル使用メモリ | 162,644 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-10-04 16:20:48 |
合計ジャッジ時間 | 2,798 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int p[1001]; for(int i=1;i<=n;i++){ cin>>p[i]; } int a=1,ans=0; while(a<=n){ if(a==n){ cout<<ans<<endl; return 0; } int minn=INT_MAX,b=0; for(int j=a;j<=n;j++){ if(p[j]<minn){ minn=p[j]; b=j; } } if(b==a){ a++; continue; } else{ swap(p[a],p[b]); a++; } ans++; } }