#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3010;
const ll inf = 1e18;
int n;
ll cp[maxn], cs[maxn], pref[maxn], bef[maxn], aft[maxn];
ll l[maxn], d[maxn], c;
ll dist[maxn];
struct edge
{
int to;
ll w;
edge(int _to = 0, ll _w = 0)
{
to = _to;
w = _w;
}
bool operator < (const edge &e) const
{
return w > e.w;
}
};
int used[maxn];
ll get_dist(int l, int r)
{
if (l > r)
swap(l, r);
return pref[r - 1] - pref[l - 1];
}
ll find_shortcut(int N, vector<int> L, vector<int> D, int C)
{
n = N;
c = C;
for (int i = 0; i < n - 1; i ++)
l[i + 1] = L[i];
for (int i = 0; i < n; i ++)
d[i + 1] = D[i];
for (int i = 1; i <= n; i ++)
{
pref[i] = pref[i - 1] + l[i];
}
for (int i = 1; i <= n; i ++)
{
cp[i] = cp[i - 1] + l[i - 1];
cp[i] = max(cp[i], d[i]);
bef[i] = bef[i - 1];
for (int j = 1; j < i; j ++)
{
bef[i] = max(bef[i], get_dist(i, j) + d[i] + d[j]);
}
}
for (int i = n; i > 0; i --)
{
cs[i] = cs[i + 1] + l[i];
cs[i] = max(cs[i], d[i]);
aft[i] = aft[i + 1];
for (int j = i + 1; j <= n; j ++)
{
aft[i] = max(aft[i], get_dist(i, j) + d[i] + d[j]);
}
}
ll ans = inf;
for (int l = 1; l <= n; l ++)
{
for (int r = l + 1; r <= n; r ++)
{
ll res = max(bef[l], aft[r]), len = pref[r - 1] - pref[l - 1] + c;
set < ll > act;
int lb = l, rb = l;
for (int i = l; i <= r; i ++)
{
/**int lf = i, rf = r;
while(lf <= rf)
{
int mf = (lf + rf) / 2;
if (get_dist(i, mf) <= len - get_dist(i, mf))
lf = mf + 1;
else
rf = mf - 1;
}*/
while(rb < r)
{
if (get_dist(i, rb + 1) < len - get_dist(i, rb + 1))
rb ++;
}
for (int j = i + 1; j <= rb; j ++)
{
ll path = get_dist(i, j) + d[i] + d[j];
if (i == l)
path = path - d[i] + cp[i];
if (j == r)
path = path - d[j] + cs[j];
res = max(res, path);
}
for (int j = rb + 1; j <= r; j ++)
{
ll path = len - get_dist(i, j) + d[i] + d[j];
if (i == l)
path = path - d[i] + cp[i];
if (j == r)
path = path - d[j] + cs[j];
res = max(res, path);
}
/**for (int j = i + 1; j <= r; j ++)
{
ll path = min(len - get_dist(i, j), get_dist(i, j)) + d[i] + d[j];
if (i == l)
path = path - d[i] + cp[i];
if (j == r)
path = path - d[j] + cs[j];
res = max(res, path);
}*/
}
///cout << "range " << l << " " << r << " "
ans = min(ans, res);
}
}
return ans;
}
Compilation message
shortcut.cpp: In function 'll find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:84:17: warning: unused variable 'lb' [-Wunused-variable]
84 | int lb = l, rb = l;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2098 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |