QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#478068 | #4928. Game With Numbers | rr | 0 | 0ms | 0kb | C++14 | 1.2kb | 2024-07-14 16:25:42 | 2024-07-14 16:25:43 |
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T>void read(T &x)
{
T f=1;x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
x*=f;
}
map<int,int>M[200005];
int P[200005],arr[200005],C1[200005],C2[200005];
bool cmp(int a,int b){return C2[a]>C2[b];}
int main() {
int T,n;read(T);
while(T--)
{
read(n);
for(int i=1;i<=n;i++) C1[i]=C2[i]=0;
for(int i=1,x;i<=n;i++)
{
M[i].clear();
read(arr[i]); P[i]=i;
if(i&1) C1[arr[i]]++;
else C2[arr[i]]++;
}
sort(P+1,P+1+n,cmp);
for(int i=1;i<=n;i++)
{
if(i&1) M[arr[i+1]][arr[i]]++;
else M[arr[i]][arr[i+1]]++;
if(arr[i]==arr[i+2]) i++;
}
int Ans=0;
for(int i=1;i<=n;i++)
{
for(auto j:M[i]) Ans=max(Ans,C1[i]+C2[j.first]-j.second);
for(int j=1;j<=n;j++)
{
if(!M[i].count(P[j])&&i!=P[j]) {Ans=max(Ans,C1[i]+C2[P[j]]);break;}
}
}
printf("%d\n",n-Ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
5 1 -5000111000 -5000222000 -15 5 2 5
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #15:
score: 0
Runtime Error
input:
20000 2 400000000000000 400000000000000 400000000000000 399999999999999 400000000000000 400000000000000 400000000000000 400000000000000 400000000000000 400000000000000 399999999999999 400000000000000 399999999999999 400000000000000 400000000000000 399999999999999 400000000000000 399999999999999 4000...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Runtime Error
Test #151:
score: 0
Runtime Error
input:
20000 200000 251159317 887191501 857733752 384683418 134050448 506121340 780905769 276370704 109535211 872899439 556774439 434676879 148563667 12737512 153656019 878376794 609869178 575053645 396025679 379898138 703697683 487484329 551835906 619319386 488957017 16140328 920609560 848562444 895060489...
output:
result:
Subtask #8:
score: 0
Runtime Error
Test #155:
score: 0
Runtime Error
input:
20000 200000 396977329688022 -8423371363214 383571122639006 99712372108087 291078785047968 388310484655305 362117849739665 -120348551555749 26985765506461 192508503736541 185676740370600 -214164742554207 352594619152236 382485504805765 -152156638968634 -12362549868218 381290775270609 -39341784805470...
output:
result:
Subtask #9:
score: 0
Skipped
Dependency #1:
0%