Submission #238020

#TimeUsernameProblemLanguageResultExecution timeMemory
238020KubinBoxes with souvenirs (IOI15_boxes)C++11
10 / 100
5 ms384 KiB
#include <bits/stdc++.h> using namespace std; long long delivery(int _n, int _k, int l, int p[]) { size_t n = _n, k = _k; vector<int> A[2]; int a = 0; A[0].reserve(n); A[1].reserve(n); for(size_t i = 0; i < n; i++) if(p[i]) { if(2*p[i] == l) a++; else if(p[i] <= l/2) A[0].push_back(p[i]); else A[1].push_back(l - p[i]); } reverse(A[1].begin(), A[1].end()); vector<int> B[2]; for(size_t t = 0; t < 2; t++) { B[t].resize(A[t].size() + 1); for(size_t i = 0; i < A[t].size(); i++) B[t][i+1] = (i+1 >= k ? B[t][i+1-k] : 0) + A[t][i]; } size_t ni = A[0].size() + A[1].size(); int64_t result = ni ? INT64_MAX : 0, base = 0; while(ni) { int64_t curr = base; for(size_t t = 0; t < 2; t++) curr += 2 * B[t][A[t].size()]; result = min(result, curr); for(size_t i = 0; i < k and ni; i++, ni--) { if(a) a--; else if(A[0].empty()) A[1].pop_back(); else if(A[1].empty()) A[0].pop_back(); else if(A[0].back() < A[1].back()) A[1].pop_back(); else A[0].pop_back(); } base += l; } result = min(result, base); return result; }
#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...