# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
531980 | hoanghq2004 | Diversity (CEOI21_diversity) | C++14 | 29 ms | 65980 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
}
컴파일 시 표준 에러 (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... |