이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
const int mxN=1e6+5;
ll st[2][4*mxN];
void upd(int v,int l,int r,int ind,ll val,int t){
if(l>ind || r<ind)
return;
if(l==r){
st[t][v]=val;
} else{
int m=(l+r)>>1;
upd(v<<1,l,m,ind,val,t);
upd(v<<1|1,m+1,r,ind,val,t);
st[t][v]=min(st[t][v<<1],st[t][v<<1|1]);
}
}
ll query(int v,int l,int r,int lq,int rq,int t){
if(lq>rq)
return 1e18;
if(l>=lq && r<=rq)
return st[t][v];
int m=(l+r)>>1;
return min(query(v<<1,l,m,lq,min(rq,m),t),query(v<<1|1,m+1,r,max(lq,m+1),rq,t));
}
ll delivery(int N, int K, int L, int positions[]){
ll ans=0;
vector<int> pos;
for(int i=0;i<N;i++){
if(positions[i])
pos.pb(positions[i]);
}
int n=sz(pos);
vector<ll> pref(n),suff(n);
fill(st[0],st[0]+4*n+5,1e18);
for(int i=0;i<n;i++){
if(i<K){
pref[i]=min(2*pos[i],L);
} else{
pref[i]=min(2*pos[i],L)+query(1,1,n,i-K+1,i,0);
}
upd(1,1,n,i+1,pref[i],0);
}
fill(st[1],st[1]+4*n+5,1e18);
for(int i=n-1;i>=0;i--){
if(n-i-1<K){
suff[i]=min(2*(L-pos[i]),L);
} else{
suff[i]=min(2*(L-pos[i]),L)+query(1,1,n,i+2,i+1+K,1);
}
upd(1,1,n,i+1,suff[i],1);
}
ans=min(pref[n-1],suff[0]);
for(int i=0;i<n-1;i++){
mina(ans,pref[i]+suff[i+1]);
}
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... |