Submission #602968

#TimeUsernameProblemLanguageResultExecution timeMemory
602968cadmiumskyDiversity (CEOI21_diversity)C++14
64 / 100
102 ms6492 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int nmax = 3e5 + 5; int freq[nmax]; static ll solve(vector<int> val) { ll total = 0; for(auto x : val) total += (ll)x * (x + 1) / 2; ll sum = 0, int1 = 0; for(auto x : val) { int1 += sum; total += (ll)x * (int1 + sum); sum += x; } return total; } int main() { int n, q; cin >> n >> q; for(int i = 0, x; i < n; i++) { cin >> x; freq[x]++; } vector<int> val; for(auto x : freq) if(x != 0) val.push_back(x); sort(val.begin(), val.end()); vector<int> l, r; for(int i = 0; i < val.size(); i++) (i % 2? r : l).push_back(val[i]); reverse(r.begin(), r.end()); copy(r.begin(), r.end(), back_inserter(l)); val = move(l); ll cst = solve(val); //for(int i = 1; i < n; i++) { //reverse(val.end() - i, val.end()); //cst = min(cst, solve(val)); //reverse(val.end() - i, val.end()); //} cout << cst << '\n'; }

Compilation message (stderr)

diversity.cpp: In function 'int main()':
diversity.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 0; i < val.size(); i++)
      |                  ~~^~~~~~~~~~~~
#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...