This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "boxes.h"
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAX_N = 1e6 + 5;
const ll infinity = 1e18;
ll dp[MAX_N];
ll Solve(vi &p, int l) {
int n = p.size();
ll ans = l;
sort(all(p));
for (int i = 0; i < n - 1; i++) {
chkmin(ans, ll(2) * (p[i] + (l - p[i + 1])));
}
chkmin(ans, ll(2) * p[n - 1]);
chkmin(ans, ll(2) * (l - p[0]));
return ans;
}
int n, k, l;
ll Solve(int ind, vi &p) {
ll ans = 0;
for (int i = 0; i < ind; i += k) {
int r = min(i + k, n);
ans += min<ll>(l, 2 * p[r - 1]);
}
for (int i = n - 1; i >= ind; i -= k) {
int left = max(ind, i - k + 1);
ans += min<ll>(l, 2 * (l - p[left]));
}
return ans;
}
long long delivery(int N, int K, int L, int P[]) {
n = N, k = K, l = L;
vi p(n);
ll ans = infinity;
for (int i = 0; i < n; i++) p[i] = P[i];
for (int ind = 0; ind <= n; ind++) {
chkmin(ans, Solve(ind, p));
}
// sort(p, p + n);
// for (int i = 0; i < n; i++) {
// vi curr;
// dp[i] = infinity;
// for (int j = i; j >= 0; j--) {
// curr.push_back(p[j]);
// if (curr.size() > k) break;
// ll x = (j > 0 ? dp[j - 1] : 0);
// chkmin(dp[i], x + Solve(curr, l));
// }
// }
// chkmin(ans, dp[n - 1]);
return ans;
}
//3 2 8
//1 2 5
Compilation message (stderr)
boxes.cpp: In function 'll Solve(vi&, int)':
boxes.cpp:21:19: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
21 | int n = p.size();
| ~~~~~~^~
# | 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... |