QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#443719#6540. Beautiful Sequencezwh2008WA 1ms5752kbC++14667b2024-06-15 16:21:212024-06-15 16:21:28

Judging History

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

  • [2024-06-15 16:21:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5752kb
  • [2024-06-15 16:21:21]
  • 提交

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],f[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]++;
	for(int i=0;i<=m;i++)f[i]=-2e9;
	for(int i=1;i<=m;i++)b[i]-=m-i-1;
	int t=0;f[0]=0;
	for(int i=m-1;i;i--) {
		for(int j=t;~j;j--) {
			if(f[j]>=b[i])f[j+1]=max(f[j+1],f[j]-b[i]-1);
		}t+=(f[t+1]!=-2e9);
	}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: 3636kb

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

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: 1ms
memory: 5680kb

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:

11
12
12
12
12
14
12
13
12
11
12
13
12
12
11
11
11
13
12
12
12
12
12
12
11
13
12
12
12
11
12
12
11
11
12
12
11
13
10
13
12
11
12
12
11
12
12
13
11
12
11
13
12
12
13
12
11
11
13
12
12
13
11
11
12
12
12
11
12
11
13
11
13
13
12
12
13
12
11
13
12
11
13
12
12
11
11
12
11
12
12
13
11
13
12
12
12
12
12
12
...

result:

wrong answer 1st numbers differ - expected: '10', found: '11'