제출 #780324

#제출 시각아이디문제언어결과실행 시간메모리
780324egekabas선물상자 (IOI15_boxes)C++14
70 / 100
2066 ms223052 KiB
#include "boxes.h" #include <bits/stdc++.h> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define pb push_back using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; const ll inf = 1e18; int n, k, l; vector<ll> calcOneSide(int dist[]){ vector<ll> dp(n+1); multiset<ll> minval = {0}; queue<pll> toerase; toerase.push({k-1, 0}); for(int i = 0; i < n; ++i){ dp[i+1] = *minval.begin() + 2*dist[i]; minval.insert(dp[i+1]); toerase.push({i+k, dp[i+1]}); while(toerase.size() && toerase.front().ff == i){ minval.erase(minval.lower_bound(toerase.front().ss)); toerase.pop(); } } return dp; } long long delivery(int N, int K, int L, int p[]) { n = N; k = K; l = L; sort(p, p+n); vector<ll> leftDp = calcOneSide(p); reverse(p, p+n); for(int i = 0; i < n; ++i){ p[i] = l-p[i]; } vector<ll> rightDp = calcOneSide(p); ll ans = inf; for(int i = 0; i <= n; ++i){ ll simpAns = leftDp[i] + rightDp[n-i]; ll compAns = leftDp[i] + l + rightDp[max(0, n-i-k)]; ans = min({ans, simpAns, compAns}); } 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...