Submission #223127

#TimeUsernameProblemLanguageResultExecution timeMemory
223127NucleistBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
6 ms640 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define EPS 0.000001 struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; ll ans,kam; map<ll,ll>gg; map<ll,ll>toz; set<ll>posi; ll dist(ll x,ll y){ return min(abs(x-y),toz[x]+toz[y]); } ll findclosest(ll x){ auto k=posi.lower_bound(x); ll n1=-1; ll n2=-1; if(k!=posi.end())n1=(*k); else{ auto d=posi.begin(); n1=(*d); } if(k!=posi.begin()){ auto f=k; f--; n2=(*f); } else{ auto l=posi.end(); l--; n2=(*l); } if(n1!=-1 && n2==-1)return n1; if(n1==-1 && n2!=-1)return n2; if(dist(x,n1)>dist(x,n2))return n2; return n1; } void solve(ll node,ll cap){ while(gg[node]>0 && cap>0){ gg[node]--,cap--; } if(gg[node]==0){ posi.erase(node); if(posi.size()!=0 && cap>0){ ll f=findclosest(node); ans+=dist(node,f); solve(f,cap); } else if(cap==0)ans+=toz[node],solve(0,kam); else if(posi.size()==0){ans+=toz[node];return;} } return; } long long delivery(int N,int K,int L,int positions[]) { kam=K; for (ll i = 0; i < N; ++i) { gg[positions[i]]++; toz[positions[i]]=min(positions[i],L-positions[i]); posi.insert(positions[i]); } solve(0,K); return ans; } //code the AC sol ! // BS/queue/map
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...