Submission #1312655

#TimeUsernameProblemLanguageResultExecution timeMemory
1312655Math4Life2020Boxes with souvenirs (IOI15_boxes)C++20
Compilation error
0 ms0 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
const ll INF = 1e18;

vector<int> p;
vector<vector<ll>> pf;
int N,K,L;

pii sfw(ll x) { //{sum forward starting at this index, # of such vertices}
    if (x>=N) {
        return {0LL,0LL};
    }
    ll r = x%K;
    ll bind = x/K;
    return {(pf[r].back()-pf[r][bind]),pf[r].size()-bind};
}

pii sbk(ll x) {
    if (x<0) {
        return {0LL,0LL};
    }
    ll r = x%K;
    ll find = x/K+1;
    return {(pf[r][find]),find};
}

long long delivery(int _N, int _K, int _L, vector<int> _p) {
    p = _p; N = _N; K = _K; L = _L;
    K = min(K,N);
    sort(p.begin(),p.end());
    pf = vector<vector<ll>>(K,vector<ll>(1,0));
    for (ll x=0;x<N;x++) {
        pf[x%K].push_back((pf[x%K].back())+p[x]);
    }
    ll ans = INF;
    for (ll t=0;t<=N;t++) {
        ll cval = 0;
        cval += 2*sbk(t-1).first;
        cval += (2*sfw(t).second*L-2*sfw(t).first);
        ans = min(ans,cval);
    }
    for (ll t=0;t<=(N-K);t++) {
        ll cval = L;
        cval += 2*sbk(t-1).first;
        cval += (2*sfw(t+K).second*L-2*sfw(t+K).first);
        ans = min(ans,cval);
    }
    return ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cc9tn5Zt.o: in function `main':
grader.c:(.text.startup+0x1e4): undefined reference to `delivery(int, int, int, int*)'
collect2: error: ld returned 1 exit status