# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
531980 | 2022-03-02T02:36:24 Z | hoanghq2004 | Diversity (CEOI21_diversity) | C++14 | 29 ms | 65980 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 65900 KB | Output is correct |
2 | Correct | 26 ms | 65868 KB | Output is correct |
3 | Correct | 26 ms | 65868 KB | Output is correct |
4 | Incorrect | 28 ms | 65936 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 65980 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 65980 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 65980 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 65900 KB | Output is correct |
2 | Correct | 26 ms | 65868 KB | Output is correct |
3 | Correct | 26 ms | 65868 KB | Output is correct |
4 | Incorrect | 28 ms | 65936 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 65900 KB | Output is correct |
2 | Correct | 26 ms | 65868 KB | Output is correct |
3 | Correct | 26 ms | 65868 KB | Output is correct |
4 | Incorrect | 28 ms | 65936 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |