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"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int MAXN = 1e5+5;
const int MAXM = 1e9+5;
const ll inf = (ll)MAXN*MAXM;
ll pre[MAXN];
ll max_dist[MAXN];
pli elems1[MAXN];
pli elems2[MAXN];
int n;
ll sum(int l, int r) {
if (l > r) swap(l, r);
return pre[r]-pre[l];
}
pll max(pll a, ll b) {
if (b > a.first) return pll(b, a.first);
if (b > a.second) return pll(a.first, b);
return pll(a.first, a.second);
}
bool makeable(ll cur, vector<int> d, int c) {
ll mx1 = -inf;
ll mx2 = -inf;
int j = 0;
// priority_queue<int> left;
// priority_queue<int, vector<int>, greater<int>> right;
pll lval(-inf, -inf);
pll rval(-inf, -inf);
ll sum = 0;
for (int i = 0; i < n; i++) {
while (j < n && elems2[j].first > cur+elems1[i].first) {
int v = elems2[j].second;
lval = max(lval, pre[v]+d[v]);
rval = max(rval, d[v]-pre[v]);
j++;
}
int v = elems1[i].second;
ll lv = (lval.first == pre[v]+d[v]) ? lval.second : lval.first;
ll rv = (rval.first == d[v]-pre[v]) ? rval.second : rval.first;
int mn = -1; // max val leq this
int mx = n;
while (mx > mn+1) {
int split = (mn+mx)/2;
if (2*pre[split] <= lv-rv) mn = split;
else mx = split;
}
sum = inf;
if (mn >= 0) sum = lv-pre[mn];
if (mx < n) sum = min(sum, rv+pre[mx]);
mx1 = max(mx1, c+d[v]-pre[v]+sum);
mx2 = max(mx2, c+d[v]+pre[v]+sum);
// assert(mx2 < 140);
}
for (int i = 0; i < n; i++) {
if (cur >= mx1+pre[i] && cur >= mx2-pre[i]) return 1;
}
return 0;
}
ll find_shortcut(int N, vector<int> l, vector<int> d, int c) {
n = N;
for (int i = 1; i < n; i++) pre[i] = pre[i-1]+l[i-1];
ll bval = inf;
for (int u = 0; u < n; u++) {
for (int v = u+1; v < n; v++) {
ll cur_val = 0;
for (int a = 0; a < n; a++) {
for (int b = a+1; b < n; b++) {
cur_val = max(cur_val, d[a]+d[b]+min(sum(a, b), c+sum(a, u)+sum(b, v)));
}
}
bval = min(bval, cur_val);
}
}
return bval;
}
# | 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... |