# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397825 | qwerty234 | Boxes with souvenirs (IOI15_boxes) | C++14 | 2 ms | 460 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 "boxes.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
vector <ll> val_cw, val_ccw, cf_cw, cf_ccw, dp_cw, dp_ccw;
vector <pair<ll, ll>> cw, ccw;
ll s_cw, s_ccw, add, shift_cw, shift_ccw, n_cw, n_ccw, n, k;
ll ans_cw, ans_ccw, ans, l;
void process_cw(int k) {
ll cur = 0;
dp_cw[cur] = ans_cw;
for (ll i = n_cw - 1; i >= 0; i--) {
while (cw[i].se > 0) {
cw[i].se--; cur++;
s_cw--;
shift_cw = (shift_cw + 1) % k;
ans_cw -= val_cw[shift_cw];
dp_cw[cur] = ans_cw;
}
val_cw[shift_cw] -= cf_cw[i];
}
}
void process_ccw(int k) {
ll cur = 0;
dp_ccw[cur] = ans_ccw;
for (ll i = n_ccw - 1; i >= 0; i--) {
while (ccw[i].se > 0) {
ccw[i].se--; cur++;
s_ccw--;
shift_ccw = (shift_ccw + 1) % k;
ans_ccw -= val_ccw[shift_ccw];
dp_ccw[cur] = ans_ccw;
}
val_ccw[shift_ccw] -= cf_ccw[i];
}
}
// ll delivery(int n, int k, int l, vector <ll> p) {
ll delivery(int n1, int k1, int l1, int p[]) {
ll n = (ll)n1, k = (ll)k1, l = (ll)l1;
add = 0;
cw.clear(); ccw.clear();
for (ll i = 0; i < n; i++) {
if (l % 2 == 0 && p[i] == l / 2) {
add++;
} else if (p[i] <= l / 2 && p[i] != 0) {
if (cw.size() == 0 || cw[cw.size() - 1].fi != p[i])
cw.pb({p[i], 0});
cw[cw.size() - 1].se++;
} else if (p[i] != 0) {
if (ccw.size() == 0 || ccw[ccw.size() - 1].fi != p[i])
ccw.pb({p[i], 0});
ccw[ccw.size() - 1].se++;
}
}
reverse(ccw.begin(), ccw.end());
val_cw.assign(k, 0);
val_ccw.assign(k, 0);
n_cw = cw.size();
n_ccw = ccw.size();
cf_cw.assign(n_cw, 0);
dp_cw.assign(s_cw + 1, 0);
for (ll i = 0; i < n_cw; i++) {
if (i == 0)
cf_cw[i] = cw[i].fi;
else
cf_cw[i] = cw[i].fi - cw[i - 1].fi;
}
cf_ccw.assign(n_ccw, 0);
dp_ccw.assign(s_ccw + 1, 0);
for (ll i = 0; i < n_ccw; i++) {
if (i == 0)
cf_ccw[i] = l - ccw[i].fi;
else
cf_ccw[i] = ccw[i - 1].fi - ccw[i].fi;
}
ans_cw = ans_ccw = s_cw = s_ccw = shift_cw = shift_ccw = 0;
for (ll i = n_cw - 1; i >= 0; i--) {
s_cw += cw[i].se;
val_cw[s_cw % k] += cf_cw[i];
ans_cw += (ll)((s_cw + k - 1) / k) * (ll)cf_cw[i];
}
for (ll i = n_ccw - 1; i >= 0; i--) {
s_ccw += ccw[i].se;
val_ccw[s_ccw % k] += cf_ccw[i];
ans_ccw += (ll)((s_ccw + k - 1) / k) * (ll)cf_ccw[i];
}
process_cw(k);
process_ccw(k);
ans = ((n + k - 1) / k) * l;
for (ll i = 0; i <= n_cw; i++) {
ll cnt = (i + add + k - 1) / k;
ll tmp = cnt * l, mod = cnt * k - (add + i);
ans = min(ans, 2 * dp_cw[i] + tmp + 2 * dp_ccw[min(mod, n_ccw)]);
}
return ans;
}
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... |