Submission #5907228


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
 
int main(){
  int n;
  cin >> n;
  vector<int> a(n/2), b(n/2);
  REP(i, n){
     if(i % 2){
        cin >> b[i/2];
     }
     else{
        cin >> a[i/2];
     }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<pair<int, int>> ac, bc;
  int cnt = 0, pre = -1;
  int ansa = 0, ansb = 0;
  REP(i, n/2){
     if(pre != a[i]){
        pre = a[i];
        cnt = 1;
         ac.push_back(make_pair(cnt, pre));
     }
     else{
        cnt++;
        ac[ac.size()-1].first++;
     }
      ansa = max(ansa, cnt);
  }
  cnt = 0;
  pre = -1;
  REP(i, n/2){
     if(pre != b[i]){
        pre = b[i];
        cnt = 1;
        bc.push_back(make_pair(cnt, pre));
     }
     else{
        cnt++;
        bc[bc.size()-1].first++;
     }
     ansb = max(ansb, cnt);
  }
  int ans;
   sort(ac.begin(), ac.end());
   sort(bc.begin(), bc.end());
   if(ac[ac.size()-1].second == bc[bc.size()-1].second){
      if(ac.size()==1 || bc.size()==1){
         if(ac.size()==1 && bc.size() == 1){
            ans = max(ac[ac.size()-1].first, bc[bc.size()-1].first);
            //cout << ac[ac.size()-1].first << " " << bc[bc.size()-1].first << " " << ans << endl;
         }
         else if(ac.size() == 1){
            ansa = ac[ac.size()-1].first;
            ansb = bc[bc.size()-2].first;
            ans = ansa+ansb;
         }
         else{
            ansb = ac[ac.size()-2].first;
            ansb = bc[bc.size()-1].first;
            ans = ansa+ansb;
         }
         
      }
      else{
         ans = max(ac[ac.size()-1].first+bc[bc.size()-2].first, ac[ac.size()-2].first+bc[bc.size()-1].first);
      }
   }
   else{
      ans = ac[ac.size()-1].first+bc[bc.size()-1].first;
   }
   //cout << n << " " << ans << endl;
   cout << n-ans << endl;

  return 0;
}

Submission Info

Submission Time
Task C - /\/\/\/
User tune
Language C++14 (GCC 5.4.1)
Score 300
Code Size 2090 Byte
Status AC
Exec Time 40 ms
Memory 1784 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 20
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 34 ms 1276 KB
ababa_1.txt AC 35 ms 1276 KB
eq_0.txt AC 31 ms 640 KB
eq_1.txt AC 32 ms 640 KB
rnd_17.txt AC 31 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 AC 33 ms 768 KB
top2_1.txt AC 33 ms 768 KB
top2_2.txt AC 33 ms 768 KB
top2_3.txt AC 33 ms 768 KB
top2modoki_0.txt AC 33 ms 768 KB
top2modoki_1.txt AC 33 ms 768 KB
top2modoki_2.txt AC 33 ms 768 KB
top2modoki_3.txt AC 33 ms 768 KB
vary_1.txt AC 39 ms 1784 KB
vary_2.txt AC 39 ms 1784 KB
vary_3.txt AC 40 ms 1656 KB
zoro_0.txt AC 1 ms 256 KB