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 "shortcut.h"
using namespace std;
typedef long long ll;
ll find_shortcut(int n, vector<int> l, vector<int> s, int c) {
vector<ll> dist(n);
vector<pair<ll, ll>> preMax(n), postMax(n);
preMax[0] = {s[0], 0};
for (int i = 1; i < n; i++) {
dist[i] = dist[i-1] + l[i-1];
preMax[i] = {dist[i] + s[i], i};
if (preMax[i-1].first > preMax[i].first) preMax[i] = preMax[i-1];
}
postMax[n-1] = {dist[n-1] + s[n-1], n-1};
for (int i = n-2; i >= 0; i--) {
postMax[i] = {dist[i] + s[i], i};
if (postMax[i+1].first > postMax[i].first) postMax[i] = postMax[i+1];
}
ll res = 1ll << 62ll;
for (int low = 0; low < n-1; low++) {
for (int high = low+1; high < n; high++) {
ll dia = 0;
for (int i = 0; i < n-1; i++) {
for (int j = i+1; j < n; j++) {
ll dst = min(dist[j] - dist[i], abs(dist[i] - dist[low]) + c + abs(dist[high] - dist[j])) + s[i] + s[j];
dia = max(dia, dst);
}
}
res = min(res, dia);
}
}
return res;
}
# | 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... |