QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#423177#6540. Beautiful Sequencecrazy_seaWA 1ms6004kbC++14782b2024-05-27 21:24:382024-05-27 21:24:39

Judging History

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

  • [2024-05-27 21:24:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6004kb
  • [2024-05-27 21:24:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
int T,n,a[N],t[N],b[N],w,ans,flag;
void add(int x)
{
	t[x]++;
	w=min(w,x);
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		for(int i=1;i<=n;i++) a[i]=a[i-1]+(i==1||a[i]!=a[i-1]);
		for(int i=1;i<=n;i++) b[a[i]]++;
		ans=n-a[n]+1,w=n+1,flag=0;
		for(int i=1;i<a[n];i++)
		{
			if(flag) add(b[i]),flag=0;
			else if(b[i]<=w)
			{
				if(b[i]==1) flag=1,ans++;
				else add(b[i]-1);
			}
			else
			{
				t[w]--;
				add(b[i]);
				if(w==1)
				{
					while(!t[w]) w++;
					ans++,flag=1;
				}
				else t[--w]++;
			}
		}
		for(int i=0;i<=n;i++) t[i]=a[i]=b[i]=0;
		printf("%d\n",ans-flag);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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'