이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "boxes.h"
using namespace std;
typedef long long ll;
ll delivery(int n, int k, int L, int* positions){
vector<ll> prefix(n, 0);
vector<ll> suffix(n, 0);
//~ multiset<ll> s;
for(int i = 0; i < n; i++){
ll mn = 1e18;
if(i - k < 0) mn = 0;
else mn = prefix[i-k];
//~ else mn = *s.begin();
ll cost = positions[i] + min(L - positions[i], positions[i]);
prefix[i] = mn + cost;
//~ s.insert(prefix[i]);
//~ if(i - k >= 0) s.erase(s.find(prefix[i-k]));
}
//~ s.clear();
for(int i = n-1; i >= 0; i--){
ll mn = 1e18;
if(i + k >= n) mn = 0;
else mn = suffix[i+k];
//~ else mn = *s.begin();
ll cost = L - positions[i] + min(L - positions[i], positions[i]);
suffix[i] = mn + cost;
//~ s.insert(suffix[i]);
//~ if(i + k < n) s.erase(s.find(suffix[i+k]));
}
ll ans = min(suffix[0], prefix[n-1]);
for(int i = 0; i < n-1; i++){
ans = min(ans, prefix[i] + suffix[i+1]);
}
return ans;
}
//~ int main() {
//~ int N, K, L, i;
//~ cin >> N >> K >> L;
//~ vector<int> p(N);
//~ for (i = 0; i < N; i++) {
//~ cin >> p[i];
//~ }
//~ fprintf(stdout, "%lld\n", delivery(N, K, L, p));
//~ return 0;
//~ }
# | 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... |