Submission #537829

#TimeUsernameProblemLanguageResultExecution timeMemory
537829timreizinBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
809 ms334148 KiB
#include "boxes.h" #include <vector> using namespace std; using ll = long long; ll compute(vector<ll> &a, int k) { ll res = 0; for (int i = (int)a.size() - 1; i >= 0; i -= k) res += a[i] * 2; return res; } long long delivery(int n, int k, int l, int P[]) { vector<ll> teams(n); for (int i = 0; i < n; ++i) teams[i] = P[i]; vector<ll> side, left; while (!teams.empty() && l - teams.back() < teams.back()) { side.push_back(l - teams.back()); teams.pop_back(); } ll minRes = compute(teams, k) + compute(side, k); for (int i = 0; i < k && !side.empty(); ++i) { left.push_back(side.back()); side.pop_back(); } for (int i = 0; i <= k; ++i) { if (k - i < left.size()) { side.push_back(left.back()); left.pop_back(); } minRes = min(minRes, compute(teams, k) + compute(side, k) + l); if (!teams.empty()) teams.pop_back(); } return minRes; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if (k - i < left.size())
      |             ~~~~~~^~~~~~~~~~~~~
#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...