QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637378#4925. Adjacent Pairsyjs_0 3ms16072kbC++142.1kb2024-10-13 12:29:382024-10-13 12:29:42

Judging History

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

  • [2024-10-13 12:29:42]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:16072kb
  • [2024-10-13 12:29:38]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#define pr pair<int,int>
#define mkp make_pair
using namespace std;
const int N=300000;
int n,m,s,l,cnt[2][N],t,a[N],now=1;
vector<int>nxt[N];
map<pr,int>cntpr;
bool book[N];
struct qwq
{
    int val,cnt;
}p[N];
bool cmp(qwq a,qwq b)
{
    return a.cnt>b.cnt;
}
void CLEAR()
{
	for(int i=1;i<=n;i++)
	{
		cnt[0][i]=cnt[1][i]=0;
		a[i]=p[i].val=p[i].cnt=0;
		book[i]=0;
		nxt[i].clear();
	}
//	cntpr.clear();
}
int main()
{
//	freopen("qwq.in","r",stdin);
//	freopen("a.out","w",stdout);
    scanf("%d",&t);
    for(;t;t--)
    {
        scanf("%d",&n);
        cntpr.clear();
        for(int i=1;i<=n;i++)
        {
        	nxt[i].clear();
        	cnt[0][i]=cnt[1][i]=0;
		}
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            cnt[i&1][a[i]]++;
        }
        for(int i=1;i<=n;i++)
        {
            p[i].val=i;
            p[i].cnt=cnt[0][i];
        }
        sort(p+1,p+1+n,cmp);
        now=1;
        while(now<n)
        {
        	int val1=a[now];
        	int val2=a[now+1];
        	int id=now;
        	int siz=0;
        	for(;now<=n;now++)
        	{
        		if(a[now]==val1||a[now]==val2)
        			siz++;
        		else
        			break;
			}
			now--;
        	if(id&1)
        	{
        		nxt[val2].push_back(val1);
        		cntpr[mkp(val2,val1)]+=siz/2;
			}
        	else
        	{
        		nxt[val1].push_back(val2);
        		cntpr[mkp(val1,val2)]+=siz/2;
			}
		}
        int ans=0x3f3f3f3f;
        for(int i=1;i<=n;i++)
        {
            for(auto y:nxt[i])
            {
        	    book[y]=1;
                ans=min(ans,n-cnt[1][i]-cnt[0][y]+cntpr[mkp(i,y)]);
            }
            int now;
            for(now=1;book[p[now].val];now++);
            if(now<=n)
                ans=min(ans,n-cnt[1][i]-p[now].cnt);
            for(auto y:nxt[i])
                book[y]=0;
        }
        printf("%d\n",ans);
        for(int i=1;i<=n;i++)
            cnt[0][i]=cnt[1][i]=0;
    }
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 14204kb

input:

2
5
4 5 2 4 5
2
1 2

output:

3
0

result:

ok 2 lines

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 16072kb

input:

1
9
1 2 1 2 3 1 2 1 2

output:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%