Submission #946421

# Submission time Handle Problem Language Result Execution time Memory
946421 2024-03-14T16:16:59 Z Sokol080808 Candies (JOI18_candies) C++17
100 / 100
1128 ms 14284 KB
#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <malloc.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) {in >> p.first >> p.second; return in;}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2>& p) {out << p.first << ' ' << p.second; return out;}
template<typename T> istream& operator>>(istream& in, vector<T>& v) {for (auto& x : v) in >> x; return in;}
template<typename T> ostream& operator<<(ostream& out, vector<T>& v) {for (auto& x : v) out << x << ' '; return out;}
template<typename T> ostream& operator<<(ostream& out, set<T>& v) {for (auto& x : v) out << x << ' '; return out;}
template<typename T> ostream& operator<<(ostream& out, multiset<T>& v) {for (auto& x : v) out << x << ' '; return out;}

const int MAX_INT = 2147483647;
const double pi = acos(-1.0);
const int mod = 1e9 + 7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<ll> getmax(const vector<ll>& a, const vector<ll>& b) {
    int n = max(a.size(), b.size());
    vector<ll> res(n, -9e18);
    for (int i = 0; i < n; i++) {
        if (i < a.size()) res[i] = max(res[i], a[i]);
        if (i < b.size()) res[i] = max(res[i], b[i]);
    }
    return res;
}

vector<ll> conv(const vector<ll>& a, const vector<ll>& b) {
    vector<ll> d;
    for (int i = 0; i + 1 < a.size(); i++) d.push_back(a[i + 1] - a[i]);
    for (int i = 0; i + 1 < b.size(); i++) d.push_back(b[i + 1] - b[i]);
    sort(rall(d));
    vector<ll> res(d.size() + 1);
    res[0] = a[0] + b[0];
    for (int i = 0; i < d.size(); i++) res[i + 1] = res[i] + d[i];
    return res;
}

vector<int> a;

using info = array<array<vector<ll>, 2>, 2>;

info solve(int l, int r) {
    if (l + 1 == r) {
        info res;
        res[0][0] = {0};
        res[0][1] = {-(ll)1e18};
        res[1][0] = {-(ll)1e18};
        res[1][1] = {0, a[l]};
        return res;
    }

    int m = (l + r) / 2;
    info left = solve(l, m);
    info right = solve(m, r);

    info res;
    for (int a = 0; a <= 1; a++) {
        for (int b = 0; b <= 1; b++) {
            for (int c = 0; c <= 1; c++) {
                for (int d = 0; d <= 1; d++) {
                    if (b == 1 && c == 1) continue;
                    res[a][d] = getmax(res[a][d], conv(left[a][b], right[c][d]));
                }
            }
        }
    }

    return res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    a.resize(n);
    sort(all(a));
    for (int i = 0; i < n; i++) cin >> a[i];

    info var = solve(0, n);
    vector<ll> res;
    for (int a = 0; a <= 1; a++) {
        for (int b = 0; b <= 1; b++) {
            res = getmax(res, var[a][b]);
        }
    }

    for (int i = 1; i <= (n + 1) / 2; i++) cout << res[i] << '\n';

    return 0;
}

Compilation message

candies.cpp: In function 'std::vector<long long int> getmax(const std::vector<long long int>&, const std::vector<long long int>&)':
candies.cpp:42:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         if (i < a.size()) res[i] = max(res[i], a[i]);
      |             ~~^~~~~~~~~~
candies.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         if (i < b.size()) res[i] = max(res[i], b[i]);
      |             ~~^~~~~~~~~~
candies.cpp: In function 'std::vector<long long int> conv(const std::vector<long long int>&, const std::vector<long long int>&)':
candies.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 0; i + 1 < a.size(); i++) d.push_back(a[i + 1] - a[i]);
      |                     ~~~~~~^~~~~~~~~~
candies.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int i = 0; i + 1 < b.size(); i++) d.push_back(b[i + 1] - b[i]);
      |                     ~~~~~~^~~~~~~~~~
candies.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < d.size(); i++) res[i + 1] = res[i] + d[i];
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 6 ms 508 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 6 ms 604 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 5 ms 544 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 6 ms 604 KB Output is correct
12 Correct 6 ms 604 KB Output is correct
13 Correct 5 ms 612 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 5 ms 856 KB Output is correct
19 Correct 5 ms 604 KB Output is correct
20 Correct 5 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 6 ms 508 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 6 ms 604 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 5 ms 544 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 6 ms 604 KB Output is correct
12 Correct 6 ms 604 KB Output is correct
13 Correct 5 ms 612 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 5 ms 856 KB Output is correct
19 Correct 5 ms 604 KB Output is correct
20 Correct 5 ms 604 KB Output is correct
21 Correct 1060 ms 12928 KB Output is correct
22 Correct 1123 ms 12928 KB Output is correct
23 Correct 1077 ms 12908 KB Output is correct
24 Correct 702 ms 12936 KB Output is correct
25 Correct 731 ms 12888 KB Output is correct
26 Correct 712 ms 12852 KB Output is correct
27 Correct 619 ms 12784 KB Output is correct
28 Correct 696 ms 12768 KB Output is correct
29 Correct 726 ms 12828 KB Output is correct
30 Correct 629 ms 12992 KB Output is correct
31 Correct 705 ms 12776 KB Output is correct
32 Correct 687 ms 12932 KB Output is correct
33 Correct 819 ms 12784 KB Output is correct
34 Correct 817 ms 13096 KB Output is correct
35 Correct 792 ms 12764 KB Output is correct
36 Correct 1128 ms 14148 KB Output is correct
37 Correct 1109 ms 14108 KB Output is correct
38 Correct 1054 ms 14260 KB Output is correct
39 Correct 758 ms 14172 KB Output is correct
40 Correct 710 ms 14156 KB Output is correct
41 Correct 716 ms 14052 KB Output is correct
42 Correct 639 ms 14240 KB Output is correct
43 Correct 656 ms 14232 KB Output is correct
44 Correct 636 ms 14244 KB Output is correct
45 Correct 677 ms 14116 KB Output is correct
46 Correct 675 ms 14240 KB Output is correct
47 Correct 677 ms 14284 KB Output is correct
48 Correct 754 ms 14068 KB Output is correct
49 Correct 738 ms 14156 KB Output is correct
50 Correct 770 ms 14224 KB Output is correct