QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422754#6540. Beautiful SequenceBronyaWA 0ms4088kbC++20771b2024-05-27 19:08:142024-05-27 19:08:15

Judging History

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

  • [2024-05-27 19:08:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4088kb
  • [2024-05-27 19:08:14]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
int n;
int a[300005];
inline int read(){
    int x = 0, t = 1;
    char ch=getchar(); 
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            t=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);  
        ch=getchar();
    }
    return x*t;
}

void Solve(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+1+n);
	int hav=0,ans=0;
	priority_queue<int>q;
	for(int i=1;i<=n;i++){
		int j=i;
		while(j<n&&a[j+1]==a[i])j++;
		ans+=j-i+1;
		if(hav<0){
			hav=-q.top();
			q.pop();
		}
		if(hav)ans--;hav--;
		q.push(-(j-i+1));
		i=j;
	}
	printf("%d\n",ans);
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--)Solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3800kb

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: 4088kb

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
15

result:

wrong answer 2nd numbers differ - expected: '17', found: '15'