This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
//#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e7 + 6;
const ll lim = 3e5 + 6;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
vector<int> v[2];
ll f[2][N],lens,k;
ll Dist(ll x,ll y){
return min(abs(x - y),lens - abs(x - y));
}
void cal(ll cond){
ll sz = v[cond].size();
for (ll i = 0;i < min(sz,k);i++){
ll now = Dist(0,v[cond][i]);
for (ll j = i;j < sz;j += k){
f[cond][j] = 2*now; now += Dist(0,v[cond][j]);
}
}
}
ll delivery(int n,int K,int L,int pos[]){
lens = L; k = K;
for (ll i = 0;i < n;i++){
if (pos[i] <= L/2) v[0].push_back(pos[i]);
else v[1].push_back(pos[i]);
}
ll sz0 = v[0].size() - 1,sz1 = v[1].size() - 1;
cal(0); cal(1); ll ans = f[0][max(0ll,sz0)] + f[1][max(0ll,sz1)]; //cout<<v[1][0]; exit(0);
for (ll i = 0;i < k;i++){
if (sz1 - i + 1 < 0||sz0 - k + i + 1 < 0) break;
ll now = f[0][sz0 - k + i + 1] + L + f[1][sz1 - i + 1];
ans = min(ans,now);
}
return ans;
}
/*
ll n,cap,L,pos[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>cap>>L;
for (ll i = 0;i < n;i++) cin>>pos[i];
cout<<delivery(n,cap,L,pos);
}
*/
Compilation message (stderr)
boxes.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
1 | #pragma GCC optimization "Ofast"
|
boxes.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
# | 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... |