제출 #747978

#제출 시각아이디문제언어결과실행 시간메모리
747978Abrar_Al_Samit선물상자 (IOI15_boxes)C++17
50 / 100
39 ms8396 KiB
#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]; bool bad[nax]; int get(int i, int j) { if(i==j) return 0; return min(a[j]-a[i], c[i]+c[i+1]+a[j]-a[i+1]); } 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+1; ++i) { dp[i] = INF; } dp[1] = c[1]; for(int i=2; i<=n; ++i) { for(int j=i-1; j>0 && i-j<=k; --j) { dp[i] = min(dp[i], dp[j] + get(j, i-1)); } dp[i] += c[i-1] + c[i]; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...