| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1326138 | ppmn_6 | Boxes with souvenirs (IOI15_boxes) | C++20 | 0 ms | 0 KiB |
#include "bits/stdc++.h"
#include "boxes.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// https://codeforces.com/blog/entry/79148
class Timer: chrono::high_resolution_clock {
const time_point start_time;
public:
Timer(): start_time(now()) {}
rep elapsed_time() const {
return chrono::duration_cast<chrono::milliseconds>(now() - start_time).count();
}
} timer;
ll delivery(int n, int k, ll l, vector<int> v) {
deque<ll> pos(n);
ll ans = 0;
for (int i = 0; i < n; i++) {
pos[i] = v[i];
}
auto dist = [&] (ll x, ll y) {
if (x > y) {
swap(x, y);
}
return min(y - x, l - y + x);
};
auto trip = [&] (int x) {
ll cur = 0;
for (int i = 0; i < x; i++) {
if (dist(cur, pos.front()) <= dist(cur, pos.back())) {
ans += dist(cur, pos.front());
cur = pos.front();
pos.pop_front();
}
else {
ans += dist(cur, pos.back());
cur = pos.back();
pos.pop_back();
}
}
ans += dist(0, cur);
};
trip(n % k);
for (int i = 0; i < n / k; i++) {
trip(k);
}
return ans;
}
