이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "boxes.h"
using namespace std;
#define MAX 1000006
#define ll long long
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define inf 100000000000000000
int Left[MAX],Right[MAX];
ll sumR[MAX],sumL[MAX];
long long delivery(int N, int K, int L, int P[]) {
int curL=0,curR=0;
int pro=0;
for(int i=0;i<N;i++) {
if(P[i]==0) continue ;
if(P[i]<=(L-1)/2) {
Left[curL++]=P[i];
}
else if(P[i]>=(L%2?(L+1)/2:L/2+1)) {
Right[curR++]=P[i];
}
else {
pro++;
}
}
//printf("PRO-->%d\n",pro);
//printf("curL-->%d curR-->%d\n",curL,curR);
reverse(Right,Right+curR);
for(int i=0;i<curR;i++) {
if(i-K>=0) sumR[i]=sumR[i-K]+(L-Right[i])*2;
else sumR[i]=(L-Right[i])*2;
}
for(int i=0;i<curL;i++) {
if(i-K>=0) sumL[i]=sumL[i-K]+Left[i]*2;
else sumL[i]=Left[i]*2;
}
for(int i=0;i<curL;i++) {
// printf("sumL[%d]-->%lld\n",i,sumL[i]);
// printf("Left[%d]-->%d\n",i,Left[i]);
}
for(int i=0;i<curR;i++) {
// printf("sumR[%d]-->%lld\n",i,sumR[i]);
// printf("Right[%d]-->%d\n",i,Right[i]);
}
ll ans=(pro+K-1)/K*L;
//printf("FIRST ANS-->%lld\n",ans);
int rem=(pro?K-pro%K:0);
ll add=inf;
int curpR=curR-1;
int curpL=curL-1;
for(int i=0;;i++,rem+=K) {
if(curpR<0 && curpL<0) break ;
while(rem>0) {
if(curpR>=0 && sumR[curpR]-(curpR-1>=0?sumR[curpR-1]:0)>sumL[curpL]-(curpL-1>=0?sumL[curpL-1]:0)) curpR--;
else if(curpL>=0) curpL--;
rem--;
}
umin(add,1ll*L*i+(curpR>=0?sumR[curpR]:0)+(curpL>=0?sumL[curpL]:0));
}
return ans+add;
}
# | 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... |