fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5.  
  6. int solve(int n, vector<int>& a) {
  7. map<int, int> mp;
  8. int ans = 0;
  9.  
  10. for (auto x : a) {
  11. mp[x]++;
  12. ans = max(ans, mp[x]);
  13. }
  14.  
  15. int odd = 0;
  16. map<int, int> even;
  17.  
  18. for (auto x : a) {
  19. if (x & 1) {
  20. odd++;
  21. } else {
  22. int d = x / 2 - 1;
  23. even[d % 2]++;
  24. }
  25. }
  26.  
  27. ans = max(ans, odd);
  28.  
  29. for (auto &[x, c] : even)
  30. ans = max(ans, c);
  31.  
  32. return ans;
  33. }
  34.  
  35. int main() {
  36. ios::sync_with_stdio(false);
  37. cin.tie(nullptr);
  38.  
  39. int T;
  40. cin >> T;
  41.  
  42. while (T--) {
  43. int n;
  44. cin >> n;
  45.  
  46. vector<int> a(n);
  47. for (auto &x : a)
  48. cin >> x;
  49.  
  50. cout << solve(n, a) << '\n';
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 5308KB
stdin
5
2
1 3
4
1 1 1 2
3
6 7 8
4
2 2 2 2
5
1 10 100 1000 100000
stdout
2
3
1
4
3