Submission #6002441
Source Code Expand
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <sstream>
#include <string.h>
#include<fstream>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"490
void fo (){fflush(stdout);}
using namespace std;
map <int,int> a , b;
int main ()
{
int n ;
scanf ("%d" , &n );
for (int i =0 ,t , turn = 0 ;i < n ;i++ , turn = !turn )
{
scanf ("%d" ,&t );
if (turn)
{
a[t]++;
}else
{
b[t]++;
}
}
int ans = 0 ;
if (SZ(a) == SZ(b) && SZ(a) == 1 )
{
if (*a.begin() == *b.begin())
ans = n/2;
}else
{
pair <int,int> m1 , m2 , m11 , m22 ;
m1.f = m2.f = m11.f = m22.f = -1 ;
set<pair<int,int>> a1 , b1 ;
for (auto i : a)
{
a1.insert({i.s,i.f});
}
for (auto i : b )
{
b1.insert({i.s,i.f});
}
for (auto i : a1)
{
if (m1.f == -1 )
{
m1.f = i.s ;
m1.s = i.f ;
}else
{
m11 = m1 ;
m1.f = i.s ;
m1.s = i.f ;
}
}
for (auto i : b1 )
{
if (m2.f == -1 )
{
m2.f = i.s ;
m2.s = i.f ;
}else
{
m22 = m2 ;
m2.f = i.s ;
m2.s = i.f ;
}
}
if (m1.f != m2.f )
{
ans = n - m1.s - m2.s ;
}else
{
if (m11.f != -1 && m22.f != -1 )
{
ans = min (n-m1.s-m22.s , n - m11.s - m2.s );
}else if (m11.f != -1 )
{
ans = min (n - m11.s - m2.s , n - m1.s );
}else
{
ans = min (n-m22.s - m1.s , n - m2.s );
}
}
}
printf ("%d\n" ,ans );
return 0;
}
Submission Info
Submission Time |
|
Task |
C - /\/\/\/ |
User |
MohamedSameh |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
2004 Byte |
Status |
AC |
Exec Time |
64 ms |
Memory |
9600 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:31:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d" , &n );
^
./Main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d" ,&t );
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
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 |
35 ms |
4864 KB |
ababa_1.txt |
AC |
38 ms |
4864 KB |
eq_0.txt |
AC |
11 ms |
256 KB |
eq_1.txt |
AC |
11 ms |
256 KB |
rnd_17.txt |
AC |
11 ms |
256 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 |
17 ms |
896 KB |
top2_1.txt |
AC |
17 ms |
896 KB |
top2_2.txt |
AC |
17 ms |
896 KB |
top2_3.txt |
AC |
17 ms |
896 KB |
top2modoki_0.txt |
AC |
17 ms |
896 KB |
top2modoki_1.txt |
AC |
17 ms |
896 KB |
top2modoki_2.txt |
AC |
17 ms |
896 KB |
top2modoki_3.txt |
AC |
17 ms |
896 KB |
vary_1.txt |
AC |
64 ms |
9600 KB |
vary_2.txt |
AC |
58 ms |
9472 KB |
vary_3.txt |
AC |
44 ms |
6400 KB |
zoro_0.txt |
AC |
1 ms |
256 KB |