이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include "boxes.h"
using namespace std;
typedef long long ll;
int const NMAX = 1e7;
int arr[1 + NMAX];
ll preC[1 + NMAX];
ll sufC[1 + NMAX];
void buildPreSufC(int n, int k, int l) {
for(int i = 1;i <= n;i++) {
if(i <= k) {
preC[i] = 2 * arr[i];
} else {
preC[i] = preC[i-k] + 2 * arr[i];
}
//cerr << preC[i] << ' ';
}
//cerr << '\n';
for(int i = n;i >= 1;i--) {
if(i >= n - k) {
sufC[i] = 2 * (l - arr[i]);
} else {
sufC[i] = sufC[i+k] + 2 * (l - arr[i]);
}
//cerr << sufC[i] << ' ';
}
//cerr << '\n';
}
ll const INF = 1e18;
ll solve(int n, int k, int l) {
ll ans1 = INF;
for(int i = 0;i < n;i++) {
ans1 = min(ans1, preC[i] + sufC[i+1]);
//cerr << preC[i] + sufC[i+1] << ' ';
}
ll ans2 = INF;
//cerr << '\n';
for(int from = 0;from < n;from++) {
int to = min(n+1, from+k+1);
ans2 = min(ans2, preC[from] + sufC[to] + l);
//cerr << from << ' ' << to << ' ' << preC[from] + sufC[to] + l << "; ";
}
//cerr << '\n';
return min(ans1, ans2);
}
ll delivery(int n, int k, int l, int position[]) {
for(int i = 0;i < n;i++) {
arr[i+1] = position[i];
}
sort(arr+1, arr+n+1);
buildPreSufC(n, k, l);
return solve(n, k, l);
}
# | 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... |