제출 #1045192

#제출 시각아이디문제언어결과실행 시간메모리
1045192vanea선물상자 (IOI15_boxes)C++14
100 / 100
434 ms288652 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; using ll = long long; using ld = long double; const ll INF = 1e18; ll delivery(int n, int k, int l, int p[]) { vector<ll> dp1(n+1), dp2(n+2); for(int i = 1; i <= n; i++) { if(i <= k) { dp1[i] = p[i-1]; } else { dp1[i] = dp1[i-k]+p[i-1]+p[i-k-1]; } } for(int i = n; i >= 1; i--) { if(i+k > n) { dp2[i] = (l-p[i-1]); } else { dp2[i] = dp2[i+k] + (l-p[i-1]) + (l-p[i+k-1]); } } ll ans = INF; for(int i = 0; i <= n; i++) { ll add1 = 0, add2 = 0; if(i) add1 = min(p[i-1], (l-p[i-1])); if(i != n) add2 = min(p[i], (l-p[i])); ans = min(ans, dp1[i] + add1 + dp2[i+1] + add2); } return ans; } /* int main() { int arr[5] = {1,5,5,15,19}; cout << delivery(5, 2, 20, arr); }*/
#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...