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>
using namespace std;
#include "shortcut.h"
const int N = 3e3 + 10;
long long f[N][N];
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
if (n > 10) return 0;
assert(f[0][1] == 0);
long long ans = 1e18;
for(int x = 0; x < n; x++) for(int y = x + 1; y < n; y++) {
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) f[i][j] = (i == j ? 0 : 1e16);
for(int i = 0; i + 1 < n; i++) f[i][i + 1] = f[i + 1][i] = l[i];
f[x][y] = min(f[x][y], (long long) c);
f[y][x] = min(f[y][x], (long long) c);
for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
}
long long cost = 0;
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if (i != j) {
cost = max(cost, f[i][j] + d[i] + d[j]);
}
ans = min(ans, cost);
}
return ans;
}
#ifdef ngu
int main()
{
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n, c;
assert(2 == scanf("%d%d", &n, &c));
std::vector<int> l(n - 1);
std::vector<int> d(n);
for (int i = 0; i < n - 1; i++)
assert(1 == scanf("%d", &l[i]));
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &d[i]));
long long t = find_shortcut(n, l, d, c);
printf("%lld\n", t);
return 0;
}
#endif // ngu
# | 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... |