結果
問題 |
No.2289 順列ソート
|
ユーザー |
|
提出日時 | 2023-05-13 14:27:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 639 bytes |
コンパイル時間 | 1,739 ms |
コンパイル使用メモリ | 167,724 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-29 07:16:24 |
合計ジャッジ時間 | 2,509 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; void fast_io() { cin.tie(nullptr); ios_base::sync_with_stdio(false); } int main(void) { fast_io(); int n; cin >> n; vector<int> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; } int ans = 0; for (int i = 0; i < n - 1; i++) { int index = i + 1; for (int j = i + 1; j < n; j++) { if (p[j] < p[index]) { index = j; } } if (p[i] > p[index]) { swap(p[i], p[index]); ans++; } } cout << ans << endl; return 0; }