Submission #531980

# Submission time Handle Problem Language Result Execution time Memory
531980 2022-03-02T02:36:24 Z hoanghq2004 Diversity (CEOI21_diversity) C++14
0 / 100
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

diversity.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
diversity.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
diversity.cpp: In function 'int main()':
diversity.cpp:40:27: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   40 |             if (mask >> i & 1 ^ 1) {
      |                 ~~~~~~~~~~^~~
diversity.cpp:24:15: warning: unused variable 'tot' [-Wunused-variable]
   24 |     long long tot = 0, cur = 0, ans = 0;
      |               ^~~
diversity.cpp:24:24: warning: unused variable 'cur' [-Wunused-variable]
   24 |     long long tot = 0, cur = 0, ans = 0;
      |                        ^~~
diversity.cpp:24:33: warning: unused variable 'ans' [-Wunused-variable]
   24 |     long long tot = 0, cur = 0, ans = 0;
      |                                 ^~~
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 65980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 65980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 65980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -