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"
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
const ll maxn = 1e5+5;
ll delivery(int n, int k, int len, int pos[]){
vector<int> vc(n);
REP(i, n){
vc[i] = pos[i];
}
sort(ALL(vc));
if (k == 1){
ll ans = 0;
REP(i, n){
ans += min(pos[i], len-pos[i]);
}
return ans*2;
}
ll ans = 0;
vector<int> L, R;
vector<ll> lmod(k), rmod(k);
REP(i, n){
if (vc[i] < len-vc[i]) {
L.pb(vc[i]);
}
else {
R.pb(len-vc[i]);
}
}
sort(ALL(L), greater<int> ()); sort(ALL(R), greater<int> ());
if (SZ(L) > SZ(R)) swap(L, R);
for (int i = 0; i < SZ(L); i += k) ans += L[i];
for (int i = 0; i < SZ(R); i += k) ans += R[i];
ans *= 2;
if (SZ(L) + SZ(R) <= k) return min((ll)(len), ans);
int l = min(SZ(L), k);
int r = k-l;
FOR(i, l, SZ(L)){
lmod[i%k] += 2*L[i];
}
FOR(i, r, SZ(R)){
rmod[i%k] += 2*R[i];
}
while(l >= 0 && r <= SZ(R)){
ll cur = len;
if (l != SZ(L)) cur += lmod[l%k];
if (r != SZ(R)) cur += rmod[r%k];
ans = min(ans, cur);
if (l == 0 || r == 0){
break;
}
l--;
lmod[l%k] += 2*L[l];
rmod[r%k] -= 2*R[r];
r++;
}
return ans;
}
# | 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... |