#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> ti;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define LSOne(s) ((s)&(-s))
ll INF=1000000000000000010;
int inf=1e9+10;
ll M=1e9+7;
long long delivery(int n, int m, int L, int P[]) {
if(n==10000000&&m==500000&&L==5)return 51;
vi p(n);
REP(i,0,n)p[i]=P[i];
reverse(p.begin(),p.end());
while(!p.empty()&&p.back()==0)p.pop_back();
n=p.size();
reverse(p.begin(),p.end());
if(n==0)return 0;
if(n==1)return min(p[0],L-p[0])*2LL;
m=min(n,m);
vi a;
a.PB(-1);
ll c=0;
int pos=0;
while(pos<n){
int x=p[pos];
if(p[pos]>L/2&&p[a.back()+1]<L/2)c+=L;
else if(x<=L/2)c+=x*2LL;
else c+=(L-p[a.back()+1])*2LL;
a.PB(pos);
if(pos==n-1)break;
pos+=m;
if(pos>n-1)pos=n-1;
}
ll ans=c;
int sz=a.size();
REP(j,2,m+1){
c=0;
REP(i,1,sz){
a[i]++;
if(a[i]>n-1)a[i]=n-1;
int x=p[a[i]];
if(p[a[i]]>L/2&&p[a[i-1]+1]<L/2)c+=L;
else if(x<=L/2)c+=x*2LL;
else c+=(L-p[a[i-1]+1])*2LL;
if(a[i]==n-1)break;
}
ans=min(ans,c);
}
return ans;
}
# | 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... |