Submission #3816253


Source Code Expand

#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define DSORT(c, type) sort(ALL(c), greater<type>())

using namespace std;


pair<int, size_t> calcMode(unordered_map<int, size_t> hash){
  auto max_iterator = max_element(hash.begin(), hash.end(),
    [](const auto &a, const auto &b) -> bool {
        return (a.second < b.second);
    }
  );
  return make_pair(max_iterator->first, max_iterator->second);
}

pair<int, size_t> calcMode2(unordered_map<int, size_t> hash, int mode){
  auto max_iterator2 = max_element(hash.begin(), hash.end(),
    [&mode](const auto &a, const auto &b) -> bool {
        return (a.second < b.second && b.second != mode);
    }
  );
  if (max_iterator2->first == mode)
    return make_pair(0, 0);
  else
    return make_pair(max_iterator2->first, max_iterator2->second);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; 
  cin >> n;
  vector<int> v(n);
  unordered_map<int, size_t> hash_odd;
  unordered_map<int, size_t> hash_even;

  for(int i=0; i<n; ++i){
    cin >> v[i];

    if(i % 2 == 0){
      if(hash_odd.find(v[i]) != hash_odd.end()){
          ++hash_odd.at(v[i]);
      }else{
          hash_odd[v[i]] = 1;
      }
    }
    else{
      if(hash_even.find(v[i]) != hash_even.end()){
          ++hash_even.at(v[i]);
      }else{
          hash_even[v[i]] = 1;
      }
    }
  }
  
  auto mode_odd = calcMode(hash_odd);
  auto mode_even = calcMode(hash_even);

  if(mode_odd.first == mode_even.first){
    auto mode2_odd = calcMode2(hash_odd, mode_odd.first);
    auto mode2_even = calcMode2(hash_even, mode_even.first);
    if(mode2_odd.second > mode2_even.second)
      cout << n - mode2_odd.second - mode_even.second << endl;
    else
      cout << n - mode_odd.second - mode2_even.second << endl;
  }
  else
    cout << n - mode_odd.second - mode_even.second << endl;

  return 0;
}

Submission Info

Submission Time
Task C - /\/\/\/
User panda24
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2600 Byte
Status WA
Exec Time 40 ms
Memory 6832 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 3
AC × 14
WA × 6
Set Name Test Cases
Sample sample1_3132.txt, sample2_iw.txt, sample3_1111.txt
All ababa_0.txt, ababa_1.txt, eq_0.txt, eq_1.txt, rnd_17.txt, sample1_3132.txt, sample2_iw.txt, sample3_1111.txt, top2_0.txt, top2_1.txt, top2_2.txt, top2_3.txt, top2modoki_0.txt, top2modoki_1.txt, top2modoki_2.txt, top2modoki_3.txt, vary_1.txt, vary_2.txt, vary_3.txt, zoro_0.txt
Case Name Status Exec Time Memory
ababa_0.txt AC 22 ms 4748 KB
ababa_1.txt AC 22 ms 4748 KB
eq_0.txt AC 12 ms 640 KB
eq_1.txt AC 13 ms 640 KB
rnd_17.txt AC 13 ms 640 KB
sample1_3132.txt AC 1 ms 256 KB
sample2_iw.txt AC 1 ms 256 KB
sample3_1111.txt AC 1 ms 256 KB
top2_0.txt WA 15 ms 1152 KB
top2_1.txt AC 15 ms 1152 KB
top2_2.txt WA 15 ms 1152 KB
top2_3.txt WA 15 ms 1152 KB
top2modoki_0.txt WA 15 ms 1152 KB
top2modoki_1.txt WA 15 ms 1152 KB
top2modoki_2.txt AC 14 ms 1152 KB
top2modoki_3.txt AC 15 ms 1152 KB
vary_1.txt AC 33 ms 6832 KB
vary_2.txt WA 40 ms 6808 KB
vary_3.txt AC 27 ms 5168 KB
zoro_0.txt AC 1 ms 256 KB