제출 #1005048

#제출 시각아이디문제언어결과실행 시간메모리
1005048Gray선물상자 (IOI15_boxes)C++17
35 / 100
1 ms684 KiB
#include "boxes.h" #include <cassert> #include <iostream> #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; for (ll i=0; i<(ll)dist.size()-k; i++){ if (pos[dist[i].ss]<=l/2){ lsi.push_back(dist[i].ss); }else{ rsi.push_back(dist[i].ss); } } ll ans=l; 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; } for (ll i=(ll)dist.size()-k; 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 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; } // cout << aans << " " << ans << ln; // cout << "Answer: " << min(ans, aans) << 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...