Submission #928423

#TimeUsernameProblemLanguageResultExecution timeMemory
928423OAleksaBoxes with souvenirs (IOI15_boxes)C++14
0 / 100
1 ms348 KiB
#include "boxes.h" #include <bits/stdc++.h> #define f first #define s second using namespace std; long long delivery(int n, int k, int l, int p[]) { vector<int> left, right; for (int i = 0;i < n;i++) { if (p[i] <= l / 2) left.push_back(p[i]); else right.push_back(p[i]); } auto Solve = [&](vector<int> fi, vector<int> se) { long long r = 0, o = 0; for (int i = 0;i < (int)fi.size();i++) { if (o == 0) { if (i == 0) r += fi[i]; else r += fi[i - 1] + fi[i]; o = k - 1; } else { o -= 1; r += fi[i] - fi[i - 1]; } if (i == (int)fi.size() - 1) r += fi[i]; } o = 0; for (int i = (int)se.size() - 1;i >= 0;i--) { if (o == 0) { if (i == (int)se.size() - 1) r += (l - se[i]); else r += se[i + 1] - se[i]; o = k - 1; } else { o -= 1; r += se[i + 1] - se[i]; } if (i == 0) r += (l - se[i]); } return r; }; long long ans = Solve(left, right); for (int i = 0;i < (int)left.size();i++) left[i] = l - left[i]; for (int i = 0;i < (int)right.size();i++) right[i] = l - right[i]; reverse(left.begin(), left.end()); return min(ans, Solve(right, left)); } /* 3 2 8 1 2 5 */
#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...