# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1034338 | 2024-07-25T12:29:04 Z | vjudge1 | 비교 (balkan11_cmp) | C++17 | 0 ms | 0 KB |
#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(); } }