結果
問題 |
No.1604 Swap Sort:ONE
|
ユーザー |
|
提出日時 | 2022-09-07 06:38:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 535 bytes |
コンパイル時間 | 1,619 ms |
コンパイル使用メモリ | 195,816 KB |
最終ジャッジ日時 | 2025-02-07 03:17:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ll n; std::cin >> n; vector<ll> a(n),b(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; a[i]--; b[a[i]]=i; } ll ans = 0; for (int i = 0; i < n; i++) { while(a[i]!=i){ ll now = a[i]; swap(a[i],a[b[a[i]-1]]); swap(b[now],b[now-1]); ans++; } } std::cout << ans << std::endl; }