이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
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];
}
void dijkstra(int s, int l, int r)
{
for (int i = 1; i <= n; i ++)
dist[i] = 1e18, used[i] = 0;
for (int i = 1; i <= n; i ++)
{
if (i == s)
{
dist[i] = d[s];
continue;
}
ll way = min(get_dist(i, l) + get_dist(r, s),
get_dist(i, r) + get_dist(l, s)) + c;
dist[i] = min(d[i] + d[s] + get_dist(i, s),
d[i] + d[s] + way);
}
}
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 ++)
{
cp[i] = cp[i - 1] + l[i - 1];
cp[i] = max(cp[i], d[i]);
}
for (int i = n; i > 0; i --)
{
cs[i] = cs[i + 1] + l[i];
cs[i] = max(cs[i], d[i]);
}
for (int i = 1; i <= n; i ++)
{
pref[i] = pref[i - 1] + l[i];
}
ll ans = inf;
for (int l = 1; l <= n; l ++)
{
for (int r = l + 1; r <= n; r ++)
{
ll res = 0;
for (int i = 1; i <= n; i ++)
{
for (int j = i + 1; j <= n; j ++)
{
ll way = min(get_dist(i, l) + get_dist(r, j),
get_dist(i, r) + get_dist(l, j)) + c;
ll path = min(way, get_dist(i, j)) + d[i] + d[j];
res = max(res, path);
}
}
ans = min(ans, res);
/**
dijkstra(1, l, r);
int lon = 1;
for (int i = 1; i <= n; i ++)
if (dist[i] > dist[lon])
lon = i;
dijkstra(lon, l, r);
ll res = 0;
for (int i = 1; i <= n; i ++)
res = max(res, dist[i]);
ans = min(ans, res);*/
}
}
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... |