QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639260 | #4925. Adjacent Pairs | chuangshigame | 0 | 0ms | 22924kb | C++14 | 900b | 2024-10-13 18:36:05 | 2024-10-13 18:36:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN=3e5+10;
int T,a[MAXN],jq[MAXN],o[MAXN],cntj[MAXN],cnto[MAXN],n;
map<int,int>mp[MAXN];
bool cmp1(int x,int y){
return cntj[x]>cntj[y];
}
bool cmp2(int x,int y){
return cnto[x]>cnto[y];
}
int main(){
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n+1;i++)jq[i]=o[i]=i,mp[i].clear(),cntj[i]=cnto[i]=0;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i&1)cntj[a[i]]++;
else cnto[a[i]]++;
}
sort(jq+1,jq+1+n,cmp1);
sort(o+1,o+1+n,cmp2);
for(int i=1;i<=n;i++){
if(i&1)mp[a[i]][a[i+1]]++;
else mp[a[i+1]][a[i]]++;
if(a[i]==a[i+2])++i;
}
int ans=INT_MAX;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(o[i]==jq[j])continue;
ans=min(ans,n-cnto[o[i]]-cntj[jq[j]]+mp[jq[j]][o[i]]);
if(mp[jq[j]][o[i]]==0)break;
}
}
cout<<(ans-1)<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 0ms
memory: 21928kb
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: 22468kb
input:
1 9 1 2 1 2 3 1 2 1 2
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 22924kb
input:
1 7 6 5 4 1 2 6 5
output:
4
result:
wrong answer 1st lines differ - expected: '5', found: '4'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%