fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5. const ll INF = -10000000000000;
  6.  
  7. void solve() {
  8. int n;
  9. cin >> n;
  10. vector<int> a(n);
  11. for (int &x : a) cin >> x;
  12. sort(a.begin(), a.end());
  13. int best = n-1;
  14. for (int p = 0; p < 2; ++p) {
  15. int l = -1, r = -1;
  16. for (int i = 0; i < n; ++i) {
  17. if ((a[i] & 1) == p) {
  18. if (l == -1) l = i;
  19. r = i;
  20. }
  21. }
  22. if (l != -1) {
  23. int cond = l + (n - 1 - r);
  24. best = min(best, cond);
  25. }
  26. }
  27. cout << best << "\n";
  28. }
  29.  
  30. int main(){
  31. ios::sync_with_stdio(false);
  32. cin.tie(nullptr);
  33.  
  34. int t;
  35. cin >> t;
  36. while (t--) solve();
  37.  
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 5316KB
stdin
6
2
5 2
7
3 1 4 1 5 9 2
7
2 7 4 6 9 11 5
3
1 2 1
2
2 1
8
8 6 3 6 4 1 1 6
stdout
1
0
2
1
1
3