제출 #1152985

#제출 시각아이디문제언어결과실행 시간메모리
1152985vladilius선물상자 (IOI15_boxes)C++20
70 / 100
2041 ms470056 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second const ll inf = 1e18; struct ST{ vector<ll> t; int n; ST(int ns){ n = ns; t.resize(4 * n); } void upd(int v, int tl, int tr, int p, ll x){ if (tl == tr){ t[v] = x; return; } int tm = (tl + tr) / 2, vv = 2 * v; if (p <= tm){ upd(vv, tl, tm, p, x); } else { upd(vv + 1, tm + 1, tr, p, x); } t[v] = min(t[vv], t[vv + 1]); } void upd(int p, ll x){ upd(1, 1, n, p, x); } ll get(int v, int tl, int tr, int l, int r){ if (l > tr || r < tl) return inf; if (l <= tl && tr <= r) return t[v]; int tm = (tl + tr) / 2, vv = 2 * v; return min(get(vv, tl, tm, l, r), get(vv + 1, tm + 1, tr, l, r)); } ll get(int l, int r){ if (l > r) return inf; return get(1, 1, n, l, r); } }; ll delivery(int n, int k, int L, int X[]){ vector<int> x(n + 1); for (int i = 1; i <= n; i++) x[i] = X[i - 1]; sort(x.begin() + 1, x.end()); vector<ll> dp(n + 1, inf); dp[0] = 0; ST T(n); T.upd(1, 2 * (L - x[1])); for (int i = 1; i <= n; i++){ int l = max(1, i - k + 1); dp[i] = min({dp[l - 1] + L, dp[l - 1] + 2 * x[i], T.get(l, i)}); if (i != n){ T.upd(i + 1, dp[i] + 2 * (L - x[i + 1])); } } return dp[n]; }
#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...