Submission #966165

#TimeUsernameProblemLanguageResultExecution timeMemory
966165AkibAzmainDistributing Candies (IOI21_candies)C++17
0 / 100
90 ms17640 KiB
#include "candies.h" #include <bits/stdc++.h> using namespace std; using ll = long long; std::vector<int> distribute_candies (std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) { ll n = c.size(); list < ll > lv; lv.insert (lv.end (), (ll) -1e18); for (auto &x : v) lv.insert (lv.end (), x); if (lv.size () > 2) for (auto it = prev (lv.end (), 2);; --it) { if (*it >= 0 && *next (it, 1) >= 0) *it += *next (it, 1), lv.erase (next (it, 1)); if (*it <= 0 && *next (it, 1) <= 0) *it += *next (it, 1), lv.erase (next (it, 1)); if (it == lv.begin ()) break; } if (lv.size () > 3) for (auto it = prev (lv.end (), 3);; --it) { if (next (it, 2) == lv.end ()) { if (it == lv.begin ()) break; continue; } if (*it >= 0 && *next (it, 1) <= 0 && *next (it, 2) >= 0 && *it >= -*next (it, 1) && *next (it, 2) >= -*next (it, 1)) *it += *next (it, 1) + *next (it, 2), lv.erase (next (it, 1)), lv.erase (next (it, 1)); if (*it >= 0 && *next (it, 1) <= 0 && *next (it, 2) >= 0 && -*it >= *next (it, 1) && -*next (it, 2) >= *next (it, 1)) *it += *next (it, 1) + *next (it, 2), lv.erase (next (it, 1)), lv.erase (next (it, 1)); if (it == lv.begin ()) break; } vector < ll > ss; for (auto &x : lv) ss.push_back (x); ss.push_back (0); map < ll, pair < int, bool > > mp; for (int i = ss.size () - 2; i >= 0; --i) { if (mp.count (abs (ss[i])) == 0) mp[abs (ss[i])] = { i, ss[i] >= 0 }; ss[i] += ss[i + 1]; } vector < int > ans (n); for (int i = 0; i < n; ++i) { auto it = mp.lower_bound (c[i])->second; if (it.second) ans[i] = c[i] + ss[it.first + 1]; else ans[i] = ss[it.first + 1]; } return ans; }
#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...