QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#633305#4925. Adjacent Pairsyjs_0 0ms16200kbC++142.0kb2024-10-12 15:02:332024-10-12 15:02:34

Judging History

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

  • [2024-10-12 15:02:34]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:16200kb
  • [2024-10-12 15:02:33]
  • 提交

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];
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;
}
int main()
{
    scanf("%d",&t);
    for(;t;t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            cnt[i&1][a[i]]++;
        }
        cntpr.clear();
        for(int i=1;i+1<=n;i+=2)
        {
            nxt[a[i+1]].push_back(a[i]);
            cntpr[mkp(a[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);
        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[now];now++);
            if(now<=n)
                ans=min(ans,n-cnt[1][i]-p[now].cnt);
            for(auto y:nxt[i])
                book[y]=0;
            nxt[i].clear();
        }
        cntpr.clear();
        for(int i=3;i<=n;i+=2)
        {
            nxt[a[i]].push_back(a[i-1]);
            cntpr[mkp(a[i],a[i-1])]++;
        }
        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[now];now++);
            if(now<=n)
                ans=min(ans,n-cnt[1][i]-p[now].cnt);
            for(auto y:nxt[i])
                book[y]=0;
            nxt[i].clear();
        }
        cntpr.clear();
        printf("%d\n",ans);
        for(int i=1;i<=n;i++)
            cnt[i][0]=cnt[i][1]=0;
    }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 0ms
memory: 16200kb

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%