Submission #1034079

#TimeUsernameProblemLanguageResultExecution timeMemory
1034079vjudge1Diversity (CEOI21_diversity)C++17
38 / 100
49 ms1576 KiB
#include <bits/stdc++.h> using namespace std; string abc = "abcdefghijklmnopqrstuvwxyz"; #define int long long int m = 1003; void solve(){ int n, q; cin >> n >> q; // 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 >> q >> q; 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; } for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ ans+=(j-i+1)*v[i]*v[j]; } } 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...