Submission #723408

#TimeUsernameProblemLanguageResultExecution timeMemory
723408coloboxxDistributing Candies (IOI21_candies)C++17
0 / 100
1060 ms23576 KiB
// #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("avx,avx2,sse2,sse3,ssse3,sse4,lzcnt,popcnt") #include <bits/stdc++.h> #include "candies.h" #include <ext/pb_ds/assoc_container.hpp> #define ll long long #define point pair<int, int> #define X first #define Y second #define all(x) (x).begin(), (x).end() #define pb push_back #define show(x) cerr << (#x) << " = " << x << '\n' #define print(x) if (1) {cerr << (#x) << " = "; for (auto it : x) \ cerr << it << ' '; cerr << '\n';} #define fast_io ios_base::sync_with_stdio(0), cin.tie(0) const int N = 1 << 19; const int S = 5e6 + 64; const int INF = 2e9 + 64; const ll MAX = 2e18 + 64; const int LOG = 25; const int MOD = 1e9 + 7; //998244353; const int P = 79; const int B = 800; using namespace std; using namespace __gnu_pbds; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { int n = c.size(); int q = v.size(); vector<point> a(n); for (int i = 0; i < n; ++i) a[i] = {c[i], i}; sort(all(a)); vector<ll> pref(q), suf(q); pref.front() = v.front(), suf.back() = v.back(); for (int i = 1; i < q; ++i) pref[i] = pref[i - 1] + v[i]; for (int i = q - 2; i >= 0; --i) suf[i] = suf[i + 1] + v[i]; suf.pb(0); vector<ll> mn(q), mx(q); mn[q - 1] = mx[q - 1] = pref[q - 1]; for (int i = q - 2; i >= 0; --i) mn[i] = min(mn[i + 1], pref[i]), mx[i] = max(mx[i + 1], pref[i]); vector<int> last(n), w(n), ans(n); for (int i = n - 1; i >= 0; --i) { show(i); if (i + 1 < n) last[i] = last[i + 1], w[i] = min(w[i + 1], a[i].X); else last[i] = -1; //show(i); int &j = last[i]; while (j + 1 < q && (mx[j + 1] - (j >= 0 ? pref[j] : 0) + w[i] >= a[i].X) || (mn[j + 1] - (j >= 0 ? pref[j] : 0) + w[i] <= 0)) { ++j; w[i] += v[j]; w[i] = max(0, min(a[i].X, w[i])); } ans[a[i].Y] = w[i] + suf[j + 1]; } return ans; }

Compilation message (stderr)

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:70:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   70 |             while (j + 1 < q && (mx[j + 1] - (j >= 0 ? pref[j] : 0) + w[i] >= a[i].X)
      |                    ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...