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;
#define int long long
#define INF 9223372036854775807
vector<int> p1;
vector<int> DP;
int cost(int a, int b, int c){
int ans = c;
ans = min(ans, (c-(a-1))*2);
ans = min(ans, b*2);
return ans;
}
int f(int n, int l, int k){
if(DP[n] != INF) return DP[n];
int ans = INF;
for(int i = 1; i < k; i++){
ans = min(ans, f(n-i, l, k)+cost(p1[n-i],p1[n],l));
}
DP[n] = ans;
return ans;
}
#undef int long long
long long delivery(int N, int K, int L, int p[]) {
#define int long long
DP.assign(N+1, INF);
for(int i = 0; i < N; i++){
p1.push_back(p[i]);
}
return f(N,L,K);
}
/*
signed main(){
int N, K, L;
cin >> N >> K >> L;
int tab[N];
DP.resize(N);
for(int i = 0; i < N; i++){
cin >> tab[i];
}
#undef int long long
cout << delivery(N,K,L,tab) << endl;
}
*/
Compilation message (stderr)
boxes.cpp:26:12: warning: extra tokens at end of #undef directive
#undef int long long
^~~~
# | 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... |