This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <boxes.h>
using namespace std;
typedef long long ll;
struct st{
ll w; int i;
st(){}
st(ll W, int I) : w(W), i(I) {}
};
ll delivery(int n, int k, int l, int p[]){
vector<int> t(n), d1(n+1), d2(n+1);
for(int i = 0; i < n; ++i) t[i] = p[i];
d1[0] = t[0], d2[n] = l-t[n-1];
for(int i = 1; i < n; ++i) d1[i] = t[i]-t[i-1];
for(int i = n-1; i; --i) d2[i] = d1[i] + d2[i+1];
for(int i = 1; i < n; ++i) d1[i] += d1[i-1];
for(int i = 0; i < n; ++i) d2[i] = d2[i+1];
vector<ll> dp1(n), dp2(n);
deque<st> dq; dq.emplace_back(0, -1);
for(int i = 0; i < n; ++i){
if(!dq.empty() && i-dq.front().i > k) dq.pop_front();
dp1[i] = dq.front().w+ll(d1[i]+min(d1[i], l-d1[i]));
while(!dq.empty() && dq.back().w >= dp1[i]) dq.pop_back();
dq.emplace_back(dp1[i], i);
} while(!dq.empty()) dq.pop_back();
dq.emplace_back(0, n);
for(int i = n-1; ~i; --i){
if(!dq.empty() && dq.front().i-i > k) dq.pop_front();
dp2[i] = dq.front().w+ll(d2[i]+min(d2[i], l-d2[i]));
while(!dq.empty() && dq.back().w >= dp2[i]) dq.pop_back();
dq.emplace_back(dp2[i], i);
} ll wynik = min(dp1[n-1], dp2[0]);
for(int i = 0; i < n-1; ++i) wynik = min(wynik, dp1[i]+dp2[i+1]);
return wynik;
}
# | 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... |