이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shortcut.h"
#include <algorithm>
#include <functional>
using namespace std;
typedef long long llong;
typedef pair<llong, llong> pll;
int n, c;
vector<llong> S;
vector<int> D;
vector<pll> Mord;
vector<pll> Pord;
vector<pll> Pmn1;
vector<llong> Pmn2;
const llong inf = 1e18;
int check(llong X) {
llong mxP = -inf, mxM = -inf;
llong mnP = inf, mnM = inf;
for (int i = 0, j = 0; i < n; ++i) {
llong it, v;
tie(v, it) = Mord[i];
while (j < n && Pord[j].first <= X + v) ++j;
llong mP = -inf;
for (int k = n - 1; j <= k; --k) if (Pord[k].second != it) {
mP = Pord[k].first;
break;
}
llong mM = (j < n ?
(Pmn1[j].second != it ? Pmn1[j].first : Pmn2[j]) : inf);
mxP = max(mxP, S[it] + D[it] + mP - (X - c));
mxM = max(mxM, S[it] + D[it] - mM - (X - c));
mnP = min(mnP, v + mM + (X - c));
mnM = min(mnM, v - mP + (X - c));
if (mnP < mxP) return 0;
if (mnM < mxM) return 0;
}
for (int i = 0, mn = 0, mx = 0; i < n; ++i) {
llong LB = max(mxP - S[i], S[i] - mnM);
llong UB = min(mnP - S[i], S[i] - mxM);
if (UB < LB) continue;
while (mn < n && S[mn] < LB) ++mn;
while (0 < mn && LB <= S[mn - 1]) --mn;
while (mx < n && S[mx] <= UB) ++mx;
while (0 < mx && UB < S[mx - 1]) --mx;
if (mn < mx) return 1;
}
return 0;
}
llong find_shortcut(int N, vector<int> L, vector<int> E, int C) {
n = N; c = C;
S.push_back(0);
for (int i : L) S.push_back(S.back() + i);
D = E;
llong mn = inf, e = 0;
for (int i = 0; i < n; ++i) {
e = max(e, S[i] + D[i] - mn);
mn = min(mn, S[i] - D[i]);
Mord.emplace_back(S[i] - D[i], i);
Pord.emplace_back(S[i] + D[i], i);
}
sort(Mord.begin(), Mord.end());
sort(Pord.begin(), Pord.end());
Pmn1.resize(n, pll(inf, -1)); Pmn2.resize(n, inf);
for (int i = n; i--; ) {
int it = Pord[i].second;
llong v = S[it] - D[it];
if (v < Pmn1[i].first) Pmn2[i] = Pmn1[i].first, Pmn1[i] = pll(v, it);
else if (v < Pmn2[i]) Pmn2[i] = v;
if (i) Pmn1[i - 1] = Pmn1[i], Pmn2[i - 1] = Pmn2[i];
}
sort(E.begin(), E.end());
llong s = E[n - 2] + E[n - 1];
while (s < e) {
llong m = (s + e) / 2;
if (check(m)) e = m;
else s = m + 1;
}
return s;
}
# | 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... |