# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
824802 | 2023-08-14T10:25:42 Z | andrei_boaca | Distributing Candies (IOI21_candies) | C++17 | 92 ms | 9784 KB |
#include "candies.h" #include <bits/stdc++.h> #include <vector> //#include "grader.cpp" using namespace std; typedef long long ll; typedef pair<ll,ll> pll; int n,q; vector<ll> v; vector<int> sol; ll s[200005]; vector<pll> ord; ll sufmin[200005],sufmax[200005]; std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> stanga,std::vector<int> dreapta, std::vector<int> vals) { n = c.size(); q=stanga.size(); v.resize(n); sol.resize(n); if(n<=2000&&q<=2000) { for(int z=0;z<stanga.size();z++) { int l=stanga[z]; int r=dreapta[z]; int val=vals[z]; for(int i=l;i<=r;i++) { v[i]+=val; if(v[i]<0) v[i]=0; if(v[i]>c[i]) v[i]=c[i]; } } for(int i=0;i<v.size();i++) sol[i]=v[i]; return sol; } bool ok=1; for(int i=0;i<vals.size();i++) if(vals[i]<0) ok=0; if(ok) { for(int z=0;z<vals.size();z++) { int l=stanga[z]; int r=dreapta[z]; int val=vals[z]; v[l]+=val; if(r+1<n) v[r+1]-=val; } ll suma=0; for(int i=0;i<n;i++) { suma+=v[i]; sol[i]=min(suma,1LL*c[i]); } return sol; } ok=1; for(int i=0;i<vals.size();i++) if(stanga[i]!=0||dreapta[i]!=n-1) ok=0; if(ok) { for(int i=0;i<n;i++) ord.push_back({c[i],i}); sort(ord.begin(),ord.end()); for(int i=0;i<vals.size();i++) s[i+1]=vals[i]; for(int i=1;i<=q;i++) s[i]=s[i-1]+s[i]; sufmin[q]=q; sufmax[q]=q; for(int i=q-1;i>=1;i--) { sufmax[i]=sufmax[i+1]; sufmin[i]=sufmin[i+1]; if(s[i]>s[sufmax[i]]) sufmax[i]=i; if(s[i]<s[sufmin[i]]) sufmin[i]=i; } ll poz=0; if(s[sufmin[1]]<0) poz=sufmin[1]; while(!ord.empty()) { if(poz==q) { for(auto i:ord) sol[i.second]=0; ord.clear(); break; } ll p=sufmax[poz+1]; ll val=s[p]-s[poz]; while(!ord.empty()&&ord.back().first>=val) { ll i=ord.back().second; sol[i]=s[q]-s[poz]; ord.pop_back(); } if(p==q) { for(auto i:ord) sol[i.second]=i.first; ord.clear(); break; } while(!ord.empty()) { ll i=ord.back().second; ll cc=ord.back().first; ll x=s[sufmin[p+1]]-(val-cc); if(x>=0) { sol[i]=s[q]-s[poz]-(val-cc); ord.pop_back(); } else break; } poz=sufmin[p]; } return sol; } return sol; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 3 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 92 ms | 9724 KB | Output is correct |
2 | Correct | 77 ms | 9724 KB | Output is correct |
3 | Correct | 91 ms | 9680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Incorrect | 54 ms | 4984 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Incorrect | 44 ms | 9784 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 3 ms | 340 KB | Output is correct |
6 | Correct | 92 ms | 9724 KB | Output is correct |
7 | Correct | 77 ms | 9724 KB | Output is correct |
8 | Correct | 91 ms | 9680 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Incorrect | 54 ms | 4984 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |