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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nint signed
typedef vector<int> vi;
int delivery2(nint N, nint K, nint L, nint P[], bool tryp)
{
//cout << "HELLO " << tryp << endl;
int n = N;
int k = K;
int l = L;
vi p(n);
for (int i = 0; i < n; i++)
p[i] = P[i];
vi d1(n + 1), d2(n + 1);
for (int i = 1; i <= n; i++)
d1[i] = p[i - 1];
for (int i = 1; i <= n; i++)
d2[i] = l - p[n - i];
//for (int x : d1)
// cout << x << ' ';
//cout << endl;
//for (int x : d2)
// cout << x << ' ';
//cout << endl;
int rem = n;
int a1, a2;
a1 = a2 = 0;
bool fst = true;
int res = 0;
while (rem) {
int re = min(k, rem);
int p1 = min(2 * d1[re + a1], l);
int p2 = min(2 * d2[re + a2], l);
int ch = 1e18;
int cp1 = 0;
int cp2 = 0;
if (p1 < p2) {
ch = p1;
cp1 = re;
} else {
ch = p2;
cp2 = re;
}
if (tryp) {
//ch = 1e18;
for (int i = 1; i < re; i++) {
int th = (2 * d1[i + a1]) + (2 * d2[re - i + a2]);
if (th < ch) {
ch = th;
cp1 = i;
cp2 = re - i;
}
}
}
rem -= re;
fst = false;
res += ch;
a1 += cp1;
a2 += cp2;
}
return res;
}
int delivery(nint N, nint K, nint L, nint P[])
{
return min(delivery2(N, K, L, P, false), delivery2(N, K, L, P, true));
}
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery2(int, int, int, int*, bool)':
boxes.cpp:34:10: warning: variable 'fst' set but not used [-Wunused-but-set-variable]
34 | bool fst = true;
| ^~~
# | 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... |