이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
const ll oo = 1e18;
ll delivery(int n, int k, int l, int p[]) {
vi a;
for(int i = 0; i < n; i++)
if(p[i]) a.PB(p[i]);
n = SZ(a);
vi x, y;
for(int i = 0; i < n; i++) {
if(a[i] < l - a[i]) {
x.PB(a[i]);
} else if(l - a[i] < a[i]) {
y.PB(l - a[i]);
}
}
auto go = [&] (vi tt) {
sort(ALL(tt));
V<ll> dp(SZ(tt) + 1);
for(int i = 0; i < SZ(tt); i++) {
dp[i + 1] = dp[max(0, i + 1 - k)] + tt[i] * 2;
}
V<ll> diff;
for(int i = 0; i < SZ(tt); i++)
diff.PB(dp[i + 1] - dp[i]);
assert(is_sorted(ALL(diff)));
return diff;
};
V<ll> dx = go(x), dy = go(y), aux(SZ(dx) + SZ(dy));
merge(ALL(dx), ALL(dy), aux.begin());
ll ans = 1LL * (n + k - 1) / k * l, sum = 0;
for(int i = 0; i < SZ(aux); i++) {
sum += aux[i];
ans = min(ans, sum + 1LL * (n - i - 1 + k - 1) / k * l);
}
cerr << ans << endl;
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... |