# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
435930 | 2021-06-24T01:26:19 Z | dqhungdl | Distributing Candies (IOI21_candies) | C++17 | 157 ms | 12088 KB |
#include "candies.h" #include <bits/stdc++.h> using namespace std; std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) { int n=c.size(),m=v.size(); vector<long long> S(m+1),Pmin(m+1),Pmax(m+1); S[1]=v[0]; for(int i=2;i<=m;i++) S[i]=S[i-1]+v[i-1]; Pmin.back()=Pmax.back()=S.back(); for(int i=m-1;i>=0;i--) { Pmin[i]=min(Pmin[i+1],S[i]); Pmax[i]=max(Pmax[i+1],S[i]); } vector<int> rs(n); for(int i=0;i<n;i++) { // If all updates are in range if(Pmax[0]-Pmin[0]<=c[i]) { int l=1,r=m,pivot=0; int limit=Pmin[0]; while(l<=r) { int mid=(l+r)/2; if(Pmin[mid]==limit) { l=mid+1; pivot=mid; } else r=mid-1; } rs[i]=S.back()-S[pivot]; continue; } int l=0,r=m,pivot; while(l<=r) { int mid=(l+r)/2; if(Pmax[mid]-Pmin[mid]>c[i]) { pivot=mid; l=mid+1; } else r=mid-1; } // Find the last time touching the upper wall if(Pmin[pivot]==S[pivot]) { l=pivot+1,r=m; int limit=Pmax[pivot]; while(l<=r) { int mid=(l+r)/2; if(Pmax[mid]==limit) { pivot=mid; l=mid+1; } else r=mid-1; } rs[i]=c[i]+S.back()-S[pivot]; } else { // Find the last time touching the lower wall l=pivot+1,r=m; int limit=Pmin[pivot]; while(l<=r) { int mid=(l+r)/2; if(Pmin[mid]==limit) { pivot=mid; l=mid+1; } else r=mid-1; } rs[i]=S.back()-S[pivot]; } } return rs; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 143 ms | 12000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 308 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 68 ms | 9684 KB | Output is correct |
4 | Correct | 63 ms | 2828 KB | Output is correct |
5 | Correct | 157 ms | 11972 KB | Output is correct |
6 | Correct | 150 ms | 12088 KB | Output is correct |
7 | Incorrect | 134 ms | 11972 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |