| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 685002 | moonhero | Diversity (CEOI21_diversity) | C++14 | 1 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long N = 3e5 + 5;
long long cont (long long r) {
return (r + 1) * (r) / 2;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
vector <int> b(n), a;
map <int, int> cnt;
for (int i = 0; i < n; i++) {
cin >> b[i];
cnt[b[i]]++;
} for (auto it : cnt) a.push_back(it.second);
n = a.size();
int l, r; cin >> l >> r;
ll ans = 0;
for (int i = 0; i < a.size(); i++) {
ll k = 2, nwres = a[i];
for (int j = i + 1; j < a.size(); j++) {
nwres += k * a[j], k++;
} ans += nwres * a[i] - cont(a[i] - 1);
} map <vector <int>, int> used;
used[a] = 1;
while (next_permutation(a.begin(), a.end())) {
if (used[a]) continue;
used[a] = 1;
ll x = 0;
for (int i = 0; i < a.size(); i++) {
ll k = 2, nwres = a[i];
for (int j = i + 1; j < a.size(); j++) {
nwres += k * a[j], k++;
} x += nwres * a[i] - cont(a[i] - 1);
} ans = min(ans, x);
} cout << ans << '\n';
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
