Submission #946506

#TimeUsernameProblemLanguageResultExecution timeMemory
946506Sokol080808Candies (JOI18_candies)C++14
100 / 100
1037 ms16160 KiB
#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, -1e18); 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...