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>
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
using namespace std;
const int maxn=188500+10,LOG=17,mod=1e9+7;
int block = 200, timer = 0;
const double eps = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bt(i) (1 << (i))
//#define int ll
const int inf=2e9;
#define y1 yy
#define pii pair <int, int>
vector <int> fi, se;
ll solve(int K, int L)
{
int tek;
tek = 0;
ll S1 = 0;
ll S2 = 0;
ll ans = 0;
for(auto i : fi) S1+=i;
for(auto i : se) S2+=i;
for(int i = (int)fi.size() - 1; i >= 0; --i)
{
if(tek < fi[i])
{
tek += K;
ans += 2*i;
}
tek -= fi[i];
}
for(int i = (int)se.size() - 1; i >= 0; --i)
{
if(tek < se[i])
{
tek += K;
ans += 2*i;
}
tek -= se[i];
}
ll ret = ans;
ans = 0;
for(int i = (int)fi.size() - 1; i >= 0; --i)
{
if(tek < fi[i])
{
fi[i] -= tek;
S1 -= tek;
tek = 0;
if(S1 < K)
{
break;
}
tek += K;
ans += 2*i;
}
tek -= fi[i];
fi[i] = 0;
}
for(int i = (int)se.size() - 1; i >= 0; --i)
{
if(tek < se[i])
{
se[i] -= tek;
S2 -= tek;
tek = 0;
if(S2 < K)
{
break;
}
tek += K;
ans += 2*i;
}
tek -= se[i];
se[i] = 0;
}
ret = min(ret, ans + L);
return ret;
}
long long delivery(int N, int K, int L, int p[])
{
ll ret = 0;
N = 0;
p[0] = 0;
forn(1, i, L-1)
{
ret += p[i] / K * 2*min(i, L-i);
p[i] %= K;
N += p[i];
}
fi.clear();
se.clear();
if(L % 2 == 1)
{
int mid = L / 2;
forn(0, i, mid)
{
fi.pb(p[i]);
}
se.pb(0);
nfor(mid+1, i, L-1)
{
se.pb(p[i]);
}
return solve(K, L) + ret;
}
else
{
int mid = L / 2;
forn(0, i, mid-1)
{
fi.pb(p[i]);
}
se.pb(0);
nfor(mid + 1, i, L-1)
{
se.pb(p[i]);
}
ll ans = inf;
forn(0, i, p[mid])
{
fi.pb(i);
se.pb(p[mid]-i);
ans = min(ans, solve(K, L));
fi.pop_back();
se.pop_back();
}
return ans + ret;
}
}
# | 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... |