This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define SIZE 1000001
using namespace std;
int N,M,A[SIZE],B[SIZE],C[SIZE],D[SIZE],ans[SIZE];
vector<int>v[SIZE];
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>A[i];
B[A[i]]++;
}
for(int i=1;i<=M;i++){
int mx=0;
for(int j=1;j<=M;j++)C[j]=0;
for(int j=1;j<N;j+=2){
if(A[j]==i||A[j+1]==i)C[A[j]]++,C[A[j+1]]++;
else if(A[j]==A[j+1])C[A[j]]+=2;
}
for(int j=1;j<=M;j++)mx=max(B[j]-C[j],mx);
for(int j=1;j<=M;j++)C[j]=0;
for(int j=2;j<N;j+=2){
if(A[j]==i||A[j+1]==i)C[A[j]]++,C[A[j+1]]++;
else if(A[j]==A[j+1])C[A[j]]+=2;
}
for(int j=1;j<=M;j++)mx=max(B[j]-C[j],mx);
printf("%d\n",N-B[i]-mx);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |