Submission #1114509

#TimeUsernameProblemLanguageResultExecution timeMemory
1114509vjudge1Diversity (CEOI21_diversity)C++17
0 / 100
1 ms508 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back using pii=pair<int,int>; signed main(){ int n,q; cin>>n>>q; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } map<int,int>mp; vector<int>cnt; for(int i=0;i<n;i++){ mp[a[i]]++; } int ans=0; for(auto[f,s]:mp){ cnt.pb(s); ans+=s*(s-1)/2+s; } sort(cnt.begin(),cnt.end(),greater<int>()); int inc1=cnt[0],inc2=cnt[0],sum=cnt[0]; for(int i=1;i<n;i++){ if(inc2<inc1)swap(inc1,inc2); ans+=cnt[i]*(inc1+sum); inc1+=sum+cnt[i]; inc2+=(i+1)*cnt[i]; sum+=cnt[i]; } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...