Submission #23829

#TimeUsernameProblemLanguageResultExecution timeMemory
23829NirjhorBoxes with souvenirs (IOI15_boxes)C++14
35 / 100
2 ms380 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; int n, k, l; long long solveLeft (long long lim, int p[]) { int takenLeft = 0; long long len = 0; for (long long i = lim - 1; i >= 0; --i) { if (takenLeft == 0) { len += 2LL * p[i]; } ++takenLeft; if (takenLeft == k) { takenLeft = 0; } } return len; } long long solveRight (long long lim, int p[]) { long long len = 0; int takenRight = 0; for (long long i = lim; i < n; ++i) { if (takenRight == 0) { len += 2LL * (l - p[i]); } ++takenRight; if (takenRight == k) { takenRight = 0; } } return len; } #define debug(x) cout << #x << " = " << x << endl long long delivery (int N, int K, int L, int p[]) { int mid = (L + 1) >> 1; // debug(mid); long long half = lower_bound(p, p + N, mid) - p; // debug(half); n = N, k = K, l = L; // cout << solveLeft(half, p) << " " << solveRight(half, p) << endl; long long ret = solveLeft(half, p) + solveRight(half, p); // debug(ret); int taken = 0; long long left = half - 1, right = half; // debug(left); debug(right); while (taken < K and (left >= 0 or right < n)) { if (left >= 0 and right < n) { if (L < p[left] + p[right]) { --left; ++taken; } else { ++right; ++taken; } } else if (left >= 0) { --left; ++taken; } else { ++right; ++taken; } } // debug(left); debug(right); ret = min(ret, L + solveLeft(left + 1, p) + solveRight(right, p)); return ret; }
#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...