이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
int N,K,L;
int clst(int x){
if(x>L/2) x=L-x;
return (x)*2;
}
long long delivery(signed _n, signed _k, signed _l, signed p[]) {
N=_n;
K=_k;
L=_l;
vector<int> a(N);
vector<int> marked(N);
for (int i = 0; i < N; i++) a[i]=p[i];
sort(all(a));
int sumFULL=1e9;
int sumNOTFULL=0;
int lmt=N;
vector<int> prf1(sz(a)+1,0);
vector<int> prf2(sz(a)+1,0);
lmt=sz(a);
for (int i = 0; i < sz(a); i++) { if(a[i]>L/2) { lmt=i; break; } }
for (int i = 0; i < N; i++) {
if(i<K) prf1[i]=a[i]*2;
else prf1[i]=a[i]*2+prf1[i-K];
}
for (int i = sz(a)-1; i >= 0; i--) {
if(i>=sz(a)-K) prf2[i]=(L-a[i])*2;
else prf2[i]=(L-a[i])*2+prf2[i+K];
}
for (int i = 0; i < sz(a); i++) {
int res=L;
if(i>0) res+=prf1[i-1];
if(i<N-K) res+=prf2[i+K];
sumFULL=min(sumFULL, res);
}
for (int i = lmt-1; i >= 0; i-=K) sumNOTFULL+=a[i]*2;
for (int i = lmt; i < sz(a); i+=K) sumNOTFULL+=(L-a[i])*2;
return min(sumFULL,sumNOTFULL);
}
# | 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... |