Accepted
Code
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace chrono;
void solve() {
int n; string s;
cin >> n >> s;
auto t = s;
sort(all(t));
auto u = t;
reverse(all(u));
int c1 = 0, c2 = 0;
for (int i = 0; i < n; i++) {
c1 += s[i] != t[i];
c2 += s[i] != u[i];
}
cout << min(c1, c2)/2 << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t; cin >> t; while (t--)
solve();
}
Information
- Submit By
- Type
- Submission
- Problem
- P1016 I. Swap sort
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-07-14 18:39:47
- Judged At
- 2025-07-14 18:39:48
- Judged By
- Score
- 100
- Total Time
- 5ms
- Peak Memory
- 788.0 KiB