Submission #287225

#TimeUsernameProblemLanguageResultExecution timeMemory
287225SaboonBoxes with souvenirs (IOI15_boxes)C++17
50 / 100
2041 ms20856 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e7 + 10; const ll inf = 1e18; int n, k, L, a, b, A[maxn], B[maxn]; ll dp[maxn], pd[maxn], DP[maxn], opt[maxn]; void calc(int l, int r, int lo, int hi){ if (l >= r) return; int m = (l+r) >> 1; DP[m] = inf; for (int i = lo; i < hi; i++){ ll x = dp[m] + pd[i]; int cnt = n-m-i; cnt = (cnt+k-1)/k; x += 1LL*cnt*L; if (x < DP[m]) DP[m] = x, opt[m] = i; } calc(l, m, lo, hi); calc(m+1, r, lo, hi); // calc(l, m, lo, opt[m]+1); // calc(m+1, r, opt[m], hi); } ll delivery(int N, int K, int LL, int p[]){ n = N, k = K, L = LL; for (int i = 0; i < n; i++){ if (p[i] <= L/2) A[++a] = p[i]; else B[++b] = L-p[i]; } sort(A+1,A+a+1); sort(B+1,B+b+1); for (int i = 1; i <= a; i++){ if (i <= k) dp[i] = 2LL*A[i]; else dp[i] = dp[i-k] + 2LL*A[i]; } for (int i = 1; i <= b; i++){ if (i <= k) pd[i] = 2LL*B[i]; else pd[i] = pd[i-k] + 2LL*B[i]; } calc(0, a+1, 0, b+1); return *min_element(DP, DP+a+1); }
#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...