이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
set<pll> minval = {{0, k-1}};
set<pll> toerase = {{k-1, 0}};
for(int i = 0; i < n; ++i){
dp[i+1] = minval.begin()->ff + 2*dist[i];
minval.insert({dp[i], i+k});
toerase.insert({i+k, dp[i]});
while(toerase.size() && toerase.begin()->ff == i){
minval.erase({toerase.begin()->ss, toerase.begin()->ff});
toerase.erase(toerase.begin());
}
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |