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 "shortcut.h"
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int nax = 3005;
ll pp[nax][nax], ps[nax][nax], sp[nax][nax], ss[nax][nax];
long long find_shortcut(int n, std::vector<int> L, std::vector<int> d, int c)
{
vector<ll> p(n);
for (int i = 1; i < n; i++) p[i] = p[i-1] + L[i-1];
ll l = 0, r = 1e13, ans = 1e13;
while (l <= r) {
ll mid = (l+r)/2;
int max_l = n-1, min_r = 0;
memset(pp, 0xc0, sizeof(pp));
memset(ps, 0xc0, sizeof(ps));
memset(sp, 0x3f, sizeof(sp));
memset(ss, 0x3f, sizeof(ss));
for (int k = 0; k < n; k++) {
for (int l = k+1; l < n; l++) if (d[k] + d[l] + p[l] - p[k] > mid) {
ckmax(min_r, k);
ckmin(max_l, l);
ll cons = mid - c - d[k] - d[l];
ckmax(pp[k][l], p[k] + p[l] - cons);
ckmax(ps[k][l], p[k] - p[l] - cons);
ckmin(sp[k][l], cons + p[k] - p[l]);
ckmin(ss[k][l], cons + p[k] + p[l]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i) ckmin(ss[i][j], ss[i-1][j]);
if (j) ckmin(ss[i][j], ss[i][j-1]);
}
for (int j = n-1; j >= 0; j--) {
if (i) ckmin(sp[i][j], sp[i-1][j]);
if (j+1 < n) ckmin(sp[i][j], sp[i][j+1]);
}
}
for (int i = n-1; i >= 0; i--) {
for (int j = 0; j < n; j++) {
if (i+1 < n) ckmax(ps[i][j], ps[i+1][j]);
if (j) ckmax(ps[i][j], ps[i][j-1]);
}
for (int j = n-1; j >= 0; j--) {
if (i+1 < n) ckmax(pp[i][j], pp[i+1][j]);
if (j+1 < n) ckmax(pp[i][j], pp[i][j+1]);
}
}
bool ok = 0;
for (int i = 0; i <= max_l; i++) {
for (int j = max(min_r, i + 1); j < n; j++) if (!(p[i] + p[j] < pp[i][j] || p[i] - p[j] < ps[i][j] || p[i] - p[j] > sp[i][j] || p[i] + p[j] > ss[i][j])) {
ok = 1; break;
}
if (ok) break;
}
if (ok) ans = mid, r = mid-1;
else l = mid+1;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |