# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67774 | theknife2001 | Boxes with souvenirs (IOI15_boxes) | C++17 | 2 ms | 376 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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int N=1e7+55;
long long dp[N][2];
int n;
long long delivery(int N, int k, int L, int p[])
{
n=N;
int j=0;
for(int j=0;j<n;j++)
if(p[j])
break;
if(j==n)
return 0;
int x;
long long temp=0;
for(int i=0;i<n;i++)
{
x=k;
while(x--&&i<n)
{
while(p[i]==0)
i++;
dp[i][0]=temp+p[i];
i++;
}
i--;
temp+=p[i]+min(p[i],L-p[i]);
}
temp=0;
for(int i=n-1;i>=0;i--)
{
x=k;
while(x--&&i>=0)
{
if(p[i]==0)
break;
dp[i][1]=temp+(L-p[i]);
i--;
}
if(p[i]==0)
break;
i++;
temp+=L-p[i]+min(p[i],L-p[i]);
}
int i=0;
while(p[i]==0)
i++;
long long ans=dp[i][1]+min(p[i],L-p[i]);
for(;i<n;i++)
{
ans=min(dp[i][0]+(i+1<n?dp[i+1][1]:0)+min(p[i],L-p[i])+(i+1<n?min(p[i+1],L-p[i+1]):0),ans);
}
return ans;
}
/*
3 2 7
1 2 5
*/
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... |