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;
const int nax = 1e3 + 3;
const long long INF = 1e18;
long long dp[nax];
int n, k, L;
int a[nax];
int c[nax];
int assoc[nax];
long long delivery(int N, int K, int l, int p[]) {
n = N, k = K, L = l;
for(int i=1; i<=n; ++i) {
a[i] = p[i-1];
c[i] = min(a[i], L-a[i]);
}
for(int i=1; i<n; ++i) {
if(a[i+1]-a[i]>L/2) {
assoc[i] = a[i+1] - c[i] - c[i+1];
} else {
assoc[i] = a[i];
}
}
for(int i=1; i<=n+1; ++i) {
dp[i] = INF;
}
dp[1] = c[1];
set<pair<long long, long long>>id_val, val_id;
for(int i=2; i<=n; ++i) {
//erase from window
if(id_val.begin()->first<i-k) {
auto x = *id_val.begin();
id_val.erase(x);
swap(x.first, x.second);
val_id.erase(x);
}
if(!id_val.empty()) {
dp[i] = val_id.begin()->first;
dp[i] += c[i-1] + c[i] + a[i-1];
}
dp[i] = min(dp[i], dp[i-1] + c[i-1] + c[i]);
//insert to window
id_val.insert({i-1, dp[i-1] - assoc[i-1]});
val_id.insert({dp[i-1] - assoc[i-1], i-1});
}
long long ans = INF;
for(int i=1; i<=n; ++i) {
if(i+k-1>=n) {
ans = min(ans, a[n]-a[i]+dp[i]+c[n]);
}
}
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... |