Submission #1034340

#TimeUsernameProblemLanguageResultExecution timeMemory
1034340vjudge1Diversity (CEOI21_diversity)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; string abc = "abcdefghijklmnopqrstuvwxyz"; #define int long long int m = 1003; void solve(){ int n, qq; cin >> n >> qq; // vector<int> v(n); vector<int> a(m, 0); int r; int sz = 0; for(int i = 0; i < n; i++){ cin >> r; if(a[r]==0) sz++; a[r]++; } cin >> qq >> qq; vector<int> w, v(sz); for(int i = 0; i < m; i++){ if(a[i] != 0){ w.push_back(a[i]); } } sort(w.rbegin(), w.rend()); int st = sz/2; v[st]=w[0]; st--; int res = 2; for(int i = 1; i < sz; i++){ v[st]=w[i]; if(i%2 == 0) st-=res; else st+=res; res++; } int ans = 0; n = v.size(); for(int i = 0; i < n; i++){ ans+=v[i]*(v[i]+1)/2; } queue<int> q; int cur = 0; res = 0; for(int i = 1; i < n; i++){ cur+=(i+1)*v[i]; res+=v[i]; q.push(v[i]); } for(int i = 0; i < n-1; i++){ ans+=v[i]*cur; int a = q.front(); cur-=res; cur-=a; res-=a; } cout << ans << endl; } signed main(){ int t = 1; while(t--){ solve(); } }
#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...