QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#633321#4925. Adjacent Pairsyjs_0 0ms16196kbC++142.3kb2024-10-12 15:05:212024-10-12 15:05:22

Judging History

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

  • [2024-10-12 15:05:22]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:16196kb
  • [2024-10-12 15:05:21]
  • 提交

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)]);
//                cout<<i<<" "<<y<<" "<<ans<<endl;
            }
            book[i]=1;
            int now;
            for(now=1;book[now];now++);
            if(now<=n)
            {
                ans=min(ans,n-cnt[1][i]-p[now].cnt);
//            	cout<<i<<" "<<p[now].val<<" "<<ans<<endl; 
			}
            for(auto y:nxt[i])
                book[y]=0;
            nxt[i].clear();
            book[i]=0;
        }
        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)]);
            }
            book[i]=1;
            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();
            book[i]=0;
        }
        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: 16064kb

input:

2
5
4 5 2 4 5
2
1 2

output:

3
0

result:

ok 2 lines

Test #2:

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

input:

1
9
1 2 1 2 3 1 2 1 2

output:

6

result:

ok single line: '6'

Test #3:

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

input:

1
7
6 5 4 1 2 6 5

output:

5

result:

ok single line: '5'

Test #4:

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

input:

1
16
4 3 4 3 4 3 4 3 1 4 3 4 1 4 3 4

output:

8

result:

wrong answer 1st lines differ - expected: '10', found: '8'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%