QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472123 | #4925. Adjacent Pairs | return0114514 | 0 | 1ms | 5732kb | C++14 | 1.1kb | 2024-07-11 14:38:18 | 2024-07-11 14:38:19 |
answer
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long i64;
const int N=2e5+5;
int t=1;
int n;
int a[N];
int c1[N],c2[N];
int id[N];
bool cmp(int x,int y)
{
return c2[x]>c2[y];
}
void skr(void)
{
cin>>n;
for(int i=1;i<=n+1;i++)
{
c1[i]=c2[i]=0;
id[i]=i;
}
for(int i=1;i<=n;i++)
{
cin>>a[i];
i&1?c1[a[i]]++:c2[a[i]]++;
}
sort(id+1,id+n+1,cmp);
map<pair<int,int>,int> mp;
for(int l=1,r;l<n;l=r)
{
r=l+1;
int x=a[l],y=a[r];
if(l%2==0)
{
swap(x,y);
}
while(r<n)
{
if((r+1)%2==1&&a[r+1]!=x)
{
break;
}
if((r+1)%2==0&&a[r+1]!=y)
{
break;
}
r++;
}
mp[{x,y}]+=r-l+1>>1;
}
int ans=0;
for(int i=1;i<n;i++)
{
int x=a[i],y=a[i+1];
if(i%2==0)
{
swap(x,y);
}
ans=max(ans,c1[y]+c2[x]-mp[{x,y}]);
}
for(int i=1;i<=n+1;i++)
{
int t=1;
while(mp[{id[i],i}]||i==id[t])
{
t++;
}
ans=max(ans,c1[i]+c2[id[t]]);
}
cout<<n-ans<<'\n';
}
int main(void)
{
ios::sync_with_stdio(0);
scanf("%d",&t);
while(t--)
{
skr();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5732kb
input:
2 5 4 5 2 4 5 2 1 2
output:
0 0
result:
wrong answer 1st lines differ - expected: '3', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%