/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Wrong Answer 2ms 540.0 KiB
#3 Wrong Answer 46ms 832.0 KiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

void solve(int cs) {
  int n, k;
  cin >> n >> k;
  map<int,int> cnt;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x] += 1;
  }
  if (k & 1) {
    int mxcc = 0;
    for (auto it : cnt) {
      mxcc = max(mxcc, it.second);
    }
    cout << n - mxcc << "\n";
  } else {
    vector<int> st;
    for (auto it : cnt) {
      st.push_back(it.second);
    }
    sort(st.begin(), st.end());
    int res = 0;
    res += st.back();
    st.pop_back();
    if (st.size()) {
      res += st.back();
    }
    cout << n - res << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1062 Roy and Array
Contest
Brain Booster #4
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 18:44:18
Judged At
2024-11-11 03:22:10
Judged By
Score
5
Total Time
46ms
Peak Memory
832.0 KiB