이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
else dp[1][i]=dp[1][i+k]+2*(l-a[i]);
}
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 = 0; 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... |