이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
long long delivery(int n, int k, int l, int p[]) {
vector<pair<ll,ll>> vec;
for(ll i=0;i<n;i++){
if(vec.empty() or p[i]!=vec.back().f){
vec.push_back({p[i],1});
}
else{
auto pp=vec.back();
vec.pop_back();
vec.push_back({pp.f,pp.s+1});
}
}
auto rec=vec;
ll pos=-1;
ll sz=(ll)vec.size();
for(ll i=0;i<sz;i++){
if(vec[i].f<(l+1)/2){
pos=i;
}
}
ll res;
{
ll ans=0;
ll last1=0,last2=0;
if(pos!=-1){
ll cur=0;
while(cur<=pos){
ll left=k;
ll mx=vec[cur].f;
while(cur<=pos and left>0){
ll prv=vec[cur].s;
vec[cur].s=max(0ll,vec[cur].s-left);
left-=(prv-vec[cur].s);
mx=vec[cur].f;
if(vec[cur].s==0) cur++;
}
last1=k-left;
ans+=2ll*mx;
}
}
if(pos<sz-1){
ll cur=sz-1;
while(cur>pos){
ll left=k;
ll mn=vec[cur].f;
while(cur>pos and left>0){
ll prv=vec[cur].s;
vec[cur].s=max(0ll,vec[cur].s-left);
left-=(prv-vec[cur].s);
mn=vec[cur].f;
if(vec[cur].s==0) cur--;
}
last2=k-left;
ans+=2ll*(l-mn);
}
}
if(last1+last2<=k){
ll tmp=ans;
if(pos>=0){
tmp-=2ll*vec[pos].f;
}
if(pos<sz-1){
tmp-=2ll*(l-vec[pos+1].f);
}
tmp+=l;
ans=min(ans,tmp);
}
res=ans;
}
vec=rec;
if(pos>=0){
pos--;
ll ans=0;
ll last1=0,last2=0;
if(pos!=-1){
ll cur=0;
while(cur<=pos){
ll left=k;
ll mx=vec[cur].f;
while(cur<=pos and left>0){
ll prv=vec[cur].s;
vec[cur].s=max(0ll,vec[cur].s-left);
left-=(prv-vec[cur].s);
mx=vec[cur].f;
if(vec[cur].s==0) cur++;
}
last1=k-left;
ans+=2ll*mx;
}
}
if(pos<sz-1){
ll cur=sz-1;
while(cur>pos){
ll left=k;
ll mn=vec[cur].f;
while(cur>pos and left>0){
ll prv=vec[cur].s;
vec[cur].s=max(0ll,vec[cur].s-left);
left-=(prv-vec[cur].s);
mn=vec[cur].f;
if(vec[cur].s==0) cur--;
}
last2=k-left;
ans+=2ll*(l-mn);
}
}
if(last1+last2<=k){
ll tmp=ans;
if(pos>=0){
tmp-=2ll*vec[pos].f;
}
if(pos<sz-1){
tmp-=2ll*(l-vec[pos+1].f);
}
tmp+=l;
ans=min(ans,tmp);
}
res=min(res,ans);
pos++;
}
vec=rec;
if(pos<sz-1){
pos++;
ll ans=0;
ll last1=0,last2=0;
if(pos!=-1){
ll cur=0;
while(cur<=pos){
ll left=k;
ll mx=vec[cur].f;
while(cur<=pos and left>0){
ll prv=vec[cur].s;
vec[cur].s=max(0ll,vec[cur].s-left);
left-=(prv-vec[cur].s);
mx=vec[cur].f;
if(vec[cur].s==0) cur++;
}
last1=k-left;
ans+=2ll*mx;
}
}
if(pos<sz-1){
ll cur=sz-1;
while(cur>pos){
ll left=k;
ll mn=vec[cur].f;
while(cur>pos and left>0){
ll prv=vec[cur].s;
vec[cur].s=max(0ll,vec[cur].s-left);
left-=(prv-vec[cur].s);
mn=vec[cur].f;
if(vec[cur].s==0) cur--;
}
last2=k-left;
ans+=2ll*(l-mn);
}
}
if(last1+last2<=k){
ll tmp=ans;
if(pos>=0){
tmp-=2ll*vec[pos].f;
}
if(pos<sz-1){
tmp-=2ll*(l-vec[pos+1].f);
}
tmp+=l;
ans=min(ans,tmp);
}
res=min(res,ans);
}
return res;
}
# | 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... |