Submission #522711

#TimeUsernameProblemLanguageResultExecution timeMemory
522711InternetPerson10Distributing Candies (IOI21_candies)C++17
37 / 100
130 ms22228 KiB
#include "candies.h" #include <vector> #include <algorithm> #include <iostream> using namespace std; typedef long long ll; const ll BIG = 123456789123456789; vector<int> distribute_candies(vector<int> cInt, vector<int> lInt, vector<int> rInt, vector<int> vInt) { int n = cInt.size(); int q = vInt.size(); vector<ll> s(n+1), c(n), l(q), r(q), v(q); for(int i = 0; i < n; i++) { c[i] = cInt[i]; } for(int i = 0; i < q; i++) { l[i] = lInt[i]; r[i] = rInt[i]; v[i] = vInt[i]; } bool subtask2 = true, subtask3 = true, subtask4 = true; for(int i = 1; i < n; i++) { if(c[i] != c[i-1]) subtask3 = false; } for(int i = 0; i < q; i++) { if(v[i] < 0) subtask2 = false; if(r[i] - l[i] != n-1) subtask4 = false; } if(false) { // Subtask 1 for(int i = 0; i < q; i++) { for(int j = l[i]; j <= r[i]; j++) { s[j] += v[i]; s[j] = max(s[j], 0LL); s[j] = min(s[j], c[j]); } } } else if(subtask2) { for(int i = 0; i < q; i++) { s[l[i]] += v[i]; s[r[i]+1] -= v[i]; } for(int i = 1; i < n; i++) { s[i] += s[i-1]; } for(int i = 0; i < n; i++) { s[i] = min(s[i], c[i]); } } else if(subtask3) { } else if(subtask4) { vector<ll> qs; qs.push_back(-BIG); auto sameSign = [&]() { ll x = qs[qs.size() - 2]; ll y = qs[qs.size() - 1]; return ((x >= 0 && y >= 0) || (x <= 0 && y <= 0)); }; auto decreasingOrder = [&]() { ll x = qs[qs.size() - 2]; ll y = qs[qs.size() - 1]; return (abs(x) > abs(y)); }; for(ll g : v) { qs.push_back(g); while(qs.size() > 1) { if(sameSign() || !decreasingOrder()) { ll last = qs.back(); qs.pop_back(); qs[qs.size() - 1] += last; } else break; } } if(qs.size()%2) qs.push_back(0); qs.push_back(0); reverse(qs.begin(), qs.end()); for(ll &g : qs) g = abs(g); vector<pair<ll, int>> caps(n); for(int i = 0; i < n; i++) caps[i] = {c[i], i}; sort(caps.begin(), caps.end()); ll currCount = 0; int j = 0; for(int i = 1; i < qs.size(); i++) { if(i%2 == 0) { currCount += (qs[i-1] - qs[i-2]); } while(j != n) { if(caps[j].first > qs[i]) break; if(i%2) s[caps[j].second] = currCount + (caps[j].first - qs[i-1]); else s[caps[j].second] = currCount; j++; } } } else { } vector<int> sInt(n); for(int i = 0; i < n; i++) sInt[i] = s[i]; return sInt; }

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:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for(int i = 1; i < qs.size(); i++) {
      |                        ~~^~~~~~~~~~~
#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...