QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424610 | #6540. Beautiful Sequence | chenyitaoooo | WA | 0ms | 3800kb | C++14 | 726b | 2024-05-29 14:13:58 | 2024-05-29 14:13:59 |
Judging History
answer
#include<bits/stdc++.h>
#define Ri register int
using namespace std;
inline int rd(){
Ri ss=0;
char sp=getchar();
while(sp>57 || sp<48) sp=getchar();
while(sp>=48 && sp<=57) ss=(ss<<3)+(ss<<1)+(sp^48),sp=getchar();
return ss;
}
const int N=3e5+15;
int n,a[N],ans,su;
int main(){
int T=rd();
while(T--){
n=rd();
for(Ri i=1; i<=n; ++i) a[i]=rd();
sort(a+1,a+1+n);
ans=0;
while(a[n]==a[n-1]) n--,ans++;
n--,ans++;
su=0;
for(Ri i=1; i<=n; ++i){
int j=i;
while(a[j]==a[i]) ++j;
--j;
if(j==i){
if(su==0) su++;
else su--,ans++;
}
else{
if(su==0) ans+=(j-i);
else ans+=(j-i+1),su--;
}
i=j;
}
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3736kb
input:
2 6 1 1 2 3 3 4 5 1 2 2 3 3
output:
4 4
result:
ok 2 number(s): "4 4"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3800kb
input:
2 5 1 2 2 3 3 20 1 1 1 1 1 1 4 5 8 8 8 8 9 9 9 9 10 10 10 10
output:
4 16
result:
wrong answer 2nd numbers differ - expected: '17', found: '16'