QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#443759#6540. Beautiful Sequencezwh2008WA 0ms5660kbC++14645b2024-06-15 16:27:042024-06-15 16:27:05

Judging History

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

  • [2024-06-15 16:27:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5660kb
  • [2024-06-15 16:27:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pi=pair<int,int>;
#define fi first
#define se second
const int N=3e5+5;
int n,m,a[N],b[N];
void solve() {
	cin>>n,m=0;
	for(int i=1;i<=n;i++)cin>>a[i],b[i]=0;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)m+=a[i]!=a[i-1],b[m]++;
	int t=0,s=0;
	priority_queue<int>q;
	for(int i=m-1;i;i--) {
		if(b[i]<=s)s-=b[i],q.push(b[i]),t++;
		else if(q.size()&&q.top()>b[i])s+=q.top()-b[i],q.pop(),q.push(b[i]);
		else s++;
	}
	cout<<n-m+1+t<<'\n';
}
int main() {
//	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int tt;cin>>tt;
	while(tt--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3512kb

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
17

result:

ok 2 number(s): "4 17"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 5660kb

input:

300
14
1 1 1 2 2 2 3 3 3 4 5 5 6 6
14
1 1 1 2 2 3 3 4 4 5 5 6 7 7
14
1 1 2 2 3 4 4 4 5 5 5 6 6 6
14
1 1 2 2 3 3 3 4 5 5 5 6 6 6
14
1 1 1 1 1 1 2 2 2 2 2 3 3 3
14
1 1 1 1 1 1 1 1 1 1 1 1 1 1
14
1 2 2 3 4 5 5 6 6 6 7 8 8 8
14
1 2 2 2 2 2 3 4 5 6 7 8 9 10
14
1 2 2 3 4 4 4 5 6 6 6 6 6 7
14
1 1 2 2 2 3 3...

output:

10
9
11
11
12
14
10
9
11
11
9
10
10
9
11
11
11
9
9
12
10
9
10
10
11
10
11
11
11
11
10
8
9
9
10
10
11
13
10
12
11
11
8
10
9
11
10
10
10
8
11
10
11
9
10
10
10
10
11
11
12
9
10
10
9
10
9
10
11
11
10
10
10
10
11
10
10
10
9
9
8
10
8
11
9
11
9
11
11
12
9
8
10
8
12
11
9
11
10
10
11
10
10
9
10
9
10
10
10
11...

result:

wrong answer 33rd numbers differ - expected: '10', found: '9'