没估自己的复杂度,结果n方tle,45分,已经废了...
查看原帖
没估自己的复杂度,结果n方tle,45分,已经废了...
1097969
KnowWind楼主2024/10/26 21:07

没估自己的复杂度,结果n方tle,45分,已经废了...

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
int n,a[N],cnt,x;
map<int,int>num;
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",&x);
		if(!num[x])a[++cnt]=x;
		++num[x];
	}
	sort(a+1,a+n+1);
	for(int i=2;i<=n;++i){
		int now=num[a[i]];
		for(int j=i-1;j>=1;--j){
			now-=num[a[j]];
			if(now<0){
				num[a[j]]=-now;
				break;
			}
			num[a[j]]=0;
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i)ans+=num[a[i]];
	printf("%lld",ans);
	return 0;
}

2024/10/26 21:07
加载中...