제출 #588420

#제출 시각아이디문제언어결과실행 시간메모리
588420lorenzoferrari선물상자 (IOI15_boxes)C++17
10 / 100
1 ms212 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; using LL = long long; vector<LL> linear_cost(int n, int k, vector<int> p) { vector<LL> ans(n+1); ans[0] = 0; for (int i = 1; i <= n; ++i) { ans[i] = 2 * p[i-1] + ans[max(0, i - k)]; } return ans; } LL delivery(int n, int k, int l, int p[]) { sort(p, p + n); vector<int> v; for (int i = 0; i < n; ++i) if (p[i]) v.push_back(p[i]); n = int(v.size()); auto ca = linear_cost(n, k, v); auto rv = v; for (int& i : rv) i = l - i; reverse(rv.begin(), rv.end()); auto cb = linear_cost(n, k, rv); LL ans = 1e18; for (int i = 0; i <= n; ++i) { ans = min(ans, ca[i] + cb[n - i]); } for (int a = 0; a < n; ++a) { for (int b = l; b < n && b - a < k; ++b) { ans = min(ans, l + ca[a] + cb[n - b - 1]); } } 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...