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 "boxes.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 1e7 + 100;
ll dp1[MAXN];
ll dp2[MAXN];
long long delivery(int n, int k, int L, int p[]) {
ll res = 1e18;
for (ll i = 0;i < n;i ++){
ll id_l = (i-k+1);
if (id_l < 0)id_l = 0;
if (p[id_l] * 2 > L){
dp1[i] = -1;
continue;
}
if (i-k>=0){
dp1[i] = dp1[i-k] + min(L,p[i]*2);
}
else{
dp1[i] = min(L,p[i]*2);
}
if (i == n - 1)res = min(res,dp1[i]);
}
for (ll i = n - 1;i >= 0;i --){
if (p[i] * 2 <= L)break;
if (i + k >= n){
dp2[i] = min(L,(L-p[i])*2);
}
else{
dp2[i] = min(L,(L-p[i])*2)+dp2[i+k];
}
ll id_l = i-k;
if (id_l < 0)id_l = 0;
if (i >= 1 && p[id_l] * 2 <= L){
res = min(res,dp2[i]+dp1[i-1]);
}
if (i==0)res = min(res,dp2[i]);
}
// for (ll i = 0;i < n;i ++){
// cout<<dp1[i]<<' ';
// }
// cout<<'\n';
// for (ll i = 0;i < n;i ++){
// cout<<dp2[i]<<' ';
// }
// cout<<'\n';
return res;
}
# | 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... |