# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
531980 | hoanghq2004 | Diversity (CEOI21_diversity) | C++14 | 29 ms | 65980 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>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 3e5 + 10;
int n, q, cnt[N], a[N], m;
int maxv;
long long f[1 << 23];
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) maxv = max(maxv, a[i]), ++cnt[a[i]];
long long tot = 0, cur = 0, ans = 0;
for (int i = 1; i <= maxv; ++i) {
if (!cnt[i]) continue;
a[m++] = cnt[i];
}
memset(f, 60, sizeof(f));
f[0] = 0;
for (int mask = 0; mask < (1 << m); ++mask) {
long long tot = 0, cur = 0;
for (int i = 0; i < m; ++i)
if (mask >> i & 1) {
tot += a[i];
cur += tot;
}
for (int i = 0; i < m; ++i)
if (mask >> i & 1 ^ 1) {
f[mask ^ (1 << i)] = min(f[mask ^ (1 << i)], f[mask] + (cur + tot) * a[i] + 1LL * a[i] * (a[i] + 1) / 2);
}
}
// ans += cur * cnt[i];
// for (int j = 1; j <= cnt[i]; ++j) ans += tot + j;
// tot += cnt[i];
// cur += tot;
// }
cout << f[(1 << m) - 1];
}
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... |