Submission #977297

#TimeUsernameProblemLanguageResultExecution timeMemory
977297mannshah1211Diversity (CEOI21_diversity)C++17
14 / 100
936 ms2140 KiB
/** * author: hashman * created: **/ #include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) using Int = long long; #define seg(n) (Int(n) * Int(n + 1)) / 2 int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; --a[i]; } vector<int> f(11); for (int i = 0; i < n; i++) { ++f[a[i]]; } sort(f.begin(), f.end()); Int mn = 1e18; do { Int cur = 0, sum = 0; for (int j = 0; j < 11; j++) { cur += seg(n) - seg(n - sum - f[j]) - seg(sum); sum += f[j]; } mn = min(mn, cur); } while (next_permutation(f.begin(), f.end())); cout << mn << '\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...