QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424610#6540. Beautiful SequencechenyitaooooWA 0ms3800kbC++14726b2024-05-29 14:13:582024-05-29 14:13:59

Judging History

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

  • [2024-05-29 14:13:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3800kb
  • [2024-05-29 14:13:58]
  • 提交

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'