QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#472109#4925. Adjacent Pairsreturn01145140 0ms4128kbC++141.1kb2024-07-11 14:34:252024-07-11 14:34:26

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 14:34:26]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4128kb
  • [2024-07-11 14:34:25]
  • 提交

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];
		if(i%2==1)
		{
			c1[a[i]]++;
		}
		else
		{
			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]]);
	}
	printf("%d\n",&n-ans);
}
int main(void)
{
	ios::sync_with_stdio(0);
	scanf("%d",&t);
	while(t--)
	{
		skr();
	}
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4128kb

input:

2
5
4 5 2 4 5
2
1 2

output:

1610466740
1610466740

result:

wrong answer 1st lines differ - expected: '3', found: '1610466740'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%