Submission #1005012

#TimeUsernameProblemLanguageResultExecution timeMemory
1005012GrayBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
0 ms428 KiB
#include "boxes.h" #include <vector> #include <algorithm> #define ll long long #define ff first #define ss second #define ln "\n" using namespace std; vector<ll> pos; ll n, k, l; long long delivery(int N, int K, int L, int p[]) { n=N; k=K; l=L; pos.resize(n); vector<pair<ll, ll>> dist(n); for (ll i=0; i<n; i++){ pos[i] = p[i]; dist[i] = {min((ll)p[i], l-p[i]), i}; } sort(dist.begin(), dist.end()); vector<ll> lsi, rsi; ll li=2e18, ri=0; for (ll i=dist.size()-k; i<(ll)dist.size(); i++){ li=min(li, pos[dist[i].ss]); ri=max(ri, pos[dist[i].ss]); } for (ll i=0; i<(ll)dist.size(); i++){ if (pos[dist[i].ss]<=l/2){ lsi.push_back(dist[i].ss); }else{ rsi.push_back(dist[i].ss); } } ll ans=l; ll aans=0; for (ll i=lsi.size()-1; i>=0; i-=k){ aans+=pos[lsi[i]]*2; } for (ll i=rsi.size()-1; i>=0; i-=k){ aans+=(l-pos[rsi[i]])*2; } while (!lsi.empty() and pos[lsi.back()]>=li) {lsi.pop_back();} // cout << ln; while (!rsi.empty() and pos[rsi.back()]<=ri) {rsi.pop_back();} // cout << ln; // cout << li << " " << ri << ln; for (ll i=lsi.size()-1; i>=0; i-=k){ ans+=pos[lsi[i]]*2; } for (ll i=rsi.size()-1; i>=0; i-=k){ ans+=(l-pos[rsi[i]])*2; } // cout << aans << " " << ans << ln; return min(aans, 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...
#Verdict Execution timeMemoryGrader output
Fetching results...