Submission #519615

#TimeUsernameProblemLanguageResultExecution timeMemory
519615silverfishBoxes with souvenirs (IOI15_boxes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; using ll = long long; const ll N = 10000007, inf = 1e18+10; struct node{ ll mn = 1e18, mnpos = -1; void ins(ll v, int p){ if(v < mn){ mn = v; mnpos = p; } } }; ll dp[N], s[N]; node fen[N]; void ins(ll v, int p){ for(;p<N;p+=p&-p){ if(v < fen[p].mn){ fen[p].mn = v; fen[p].mnpos = p; } } } int get(int p){ ll mn=inf; int mnpos = -1; for(;p>0;p-=p&-p){ if(fen[p].mn < mn){ mn = fen[p].mn; mnpos = fen[p].mnpos; } } return mnpos; } ll mn(ll a, ll b){ return (a < b ? a : b); } long long delivery(int n, int k, int L, int p[]) { ll l = L; fill(dp, dp+N, inf); // sort(p, p+n); for(int i = 0; i < n; ++i){ s[i] = (i ? dp[i-1] : 0) + mn(2LL*(l-p[i]), l); ins(s[i], n-i); int pos = get(n-i+k-1); dp[i] = dp[pos-1]+mn(l, mn(2LL*p[i], 2LL*(l-p[pos]))); } return dp[n-1]; }

Compilation message (stderr)

Compilation timeout while compiling boxes