# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
567539 | ngpin04 | Boxes with souvenirs (IOI15_boxes) | C++17 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "boxes.h"
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
int pre[N];
int suf[N];
int a[N];
int n,k,l;
long long solve() {
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
pre[i] = 2 * a[i] + pre[max(0, i - k)];
for (int i = n; i >= 1; i--)
suf[i] = 2 * (l - a[i]) + suf[min(n + 1, i + k)];
// for (int i = 1; i <= n; i++)
// cerr << pre[i] << " " << suf[i] << "\n";
long long ans = 1LL * ((n + k - 1) / k) * l;
for (int t = 0; t * k < n; t++) {
int lef = n - t * k;
int lo = 0;
int hi = lef + 1;
while (hi - lo > 1) {
int mid = (lo + hi) >> 1;
int l = mid;
int r = lef - mid;
if (pre[l] < suf[n - r + 1])
lo = mid;
else
hi = mid;
}
mini(hi, lef);
for (int i = lo; i <= hi; i++) {
int x = i;
int y = lef - i;
mini(ans, 1LL * t * l + pre[x] + suf[n - y + 1]);
}
}
return ans;
}
long long delivery(int N, int K, int L, int p[]) {
n = N;
k = K;
l = L;
for (int i = 0; i < n; i++)
a[i + 1] = p[i];
return solve();
}
//#include "grader.cpp"
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |