이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
vector< int > left;
int curr = K;
int last = 0;
int currCost = 0;
for(int i = 0; i < N; i++){
left.push_back(p[i]-last + currCost);
curr--;
if(curr == 0){
curr = K;
currCost += 2*p[i];
}
currCost += p[i]-last;
last = p[i];
}
//left.push_back(L-last);
/*for(int a : left) cout << a << ' ';
cout << endl;*/
vector< int > right;
curr = K;
last = L;
currCost = 0;
for(int i = N-1; i >= 0; i--){
right.push_back(last - p[i] + currCost);
curr--;
if(curr == 0){
curr = K;
currCost += 2*(L-p[i]);
}
currCost += last - p[i];
last = p[i];
}
//right.push_back(last + currCost);
/*for(int a : right) cout << a << ' ';
cout << endl;*/
//reverse(right.begin(), right.end());
int ans = min(right[N - 1], left[N-1]) + min(L-p[N-1], p[N-1]);
for(int i = 0; i < N; i++){
if(N - 2 - i < 0) continue;
//cout << "INDEX " << i << ' ' << left[i] << ' ' << right[N-2-i] << ' ' << min(p[i], L-p[i]) << ' ' << min(p[i+1], L-p[i+1]) << endl;
//cout << p[N-2-i] << ' ' << L-p[N-2-i] << endl;
ans = min(ans, left[i] + right[N - 2 - i] + min(p[i],L-p[i]) + min(p[i+1],L-p[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... |