Submission #1108781

#TimeUsernameProblemLanguageResultExecution timeMemory
1108781KasymKNile (IOI24_nile)C++17
67 / 100
2055 ms12624 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 1e5+5; const ll INF = 1e18; array<int, 3> v[N]; ll dp[N], p[N]; struct node { int l, r; ll val; } seg[N<<2]; void build(int x, int l, int r){ seg[x].l = l, seg[x].r = r; if(l==r){ seg[x].val = INF; return; } int mid = (l+r)>>1; build(x<<1, l, mid); build(x<<1|1, mid+1, r); seg[x].val = min(seg[x<<1].val, seg[x<<1|1].val); } void update(int x, int k, ll u){ if(seg[x].l==seg[x].r){ seg[x].val = u; return; } int mid = (seg[x].l+seg[x].r)>>1; if(k<=mid) update(x<<1, k, u); else update(x<<1|1, k, u); seg[x].val = min(seg[x<<1].val, seg[x<<1|1].val); } ll query(int x, int l, int r){ if(l>r) return INF; if(seg[x].l==l and seg[x].r==r) return seg[x].val; int mid = (seg[x].l+seg[x].r)>>1; if(r <= mid) return query(x<<1, l, r); else if(l > mid) return query(x<<1|1, l, r); else return min(query(x<<1, l, mid), query(x<<1|1, mid+1, r)); } vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E){ int n = (int)W.size(); for(int i = 1; i <= n; ++i) v[i][0] = W[i-1], v[i][1] = A[i-1], v[i][2] = B[i-1]; sort(v+1, v+n+1); for(int i = 1; i <= n; ++i) p[i] = p[i-1]+v[i][1]; vector<ll> ans; build(1, 1, n); for(int &d : E){ for(int i = 1; i <= n; ++i) dp[i] = INF; dp[0] = 0; int l = 1; for(int i = 1; i <= n; ++i){ while(l<=n and v[i][0]-v[l][0]>d) l++; dp[i] = dp[i-1]+v[i][1]; umin(dp[i], query(1, l, i-1)+v[i][2]+p[i-1]); update(1, i, dp[i-1]+v[i][2]-p[i]); } ans.pb(dp[n]); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...