# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012829 | Luvidi | Boxes with souvenirs (IOI15_boxes) | C++17 | 670 ms | 293960 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
long long delivery(int N, int K, int L, int p[]) {
ll n=N,k=K,l=L;
vector<ll> v1,v2;
for(int i=0;i<n;i++){
if(p[i]<=l/2)v1.pb(p[i]);
else v2.pb(l-p[i]);
}
int l1=v1.size(),l2=v2.size();
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
ll dp1[l1+1],dp2[l2+1];
dp1[0]=dp2[0]=0;
for(int i=0;i<l1;i++){
if(i<k)dp1[i+1]=2*v1[i];
else dp1[i+1]=2*v1[i]+dp1[i-k+1];
}
for(int i=0;i<l2;i++){
if(i<k)dp2[i+1]=2*v2[i];
else dp2[i+1]=2*v2[i]+dp2[i-k+1];
}
ll ans=dp1[l1]+dp2[l2];
ans=min(ans,(n+k-1)/k*l);
for(ll i=0;i<=l1;i++){
ll x=(l1-i)/k;
dp1[i]+=l*x;
}
for(ll i=0;i<=l2;i++){
ll x=(l2-i)/k;
dp2[i]+=l*x;
}
for(ll i=l1;i&&i>l1-k+1;i--){
ll j=-i+l2-k+2+l1;
if(j<1)continue;
ll x1=1e18,x2=1e18;
for(ll z=i;z>0;z-=k)x1=min(x1,dp1[z-1]);
for(ll z=j;z>0;z-=k)x2=min(x2,dp2[z-1]);
ans=min(ans,x1+x2+l);
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |