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>
using namespace std;
using ll = long long;
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int MAXN=1e7+10;
int n,k,l,a[MAXN];
ll dp[2][MAXN],ans=1e18;
long long delivery(int N, int K, int L, int p[]) {
n=N,k=K,l=L;
for (int i = 0; i < n; ++i) a[i+1]=p[i];
for (int i = 1; i <= n; ++i) {
if (i<k) dp[0][i]=2*a[i];
else dp[0][i]=dp[0][i-k]+2*a[i];
}
for (int i = n; i >= 1; --i) {
if (i>n-k) dp[1][i]=2*(l-a[i]+1);
else dp[1][i]=dp[1][i+k]+2*(l-a[i]+1);
}
ans = min(dp[0][n],dp[1][1]);
for (int i = 1; i < n; ++i) {
chmin(ans, dp[0][i]+dp[1][i+1]);
}
for (int i = 1; i <= n-k; ++i) {
chmin(ans, dp[0][i]+dp[1][i+k+1]+l);
}
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... |