#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
long long N, C, D[509][509], A[509], B[509], dp[509];
long long solve(int cl, int cr) {
for (int i = 0; i < N; i++) dp[i] = D[0][i];
pair<long long, int> m1 = make_pair(-1LL, -1);
for (int i = 0; i < N; i++) m1 = max(m1, make_pair(dp[i] + B[i], i));
int root = m1.second;
for (int i = 0; i < N; i++) dp[i] = D[root][i];
if (dp[cl] > dp[cr] + C) { dp[cl] = dp[cr] + C; }
if (dp[cr] > dp[cl] + C) { dp[cr] = dp[cl] + C; }
for (int i = 0; i < N - 1; i++) dp[i + 1] = min(dp[i + 1], dp[i] + D[i][i + 1]);
for (int i = N - 2; i >= 0; i--) dp[i] = min(dp[i], dp[i + 1] + D[i][i + 1]);
pair<long long, int> m2 = make_pair(B[root], root);
for (int i = 0; i < N; i++) { if (i == root) continue; m2 = max(m2, make_pair(dp[i] + B[i] + B[root], i)); }
return m2.first;
}
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) {
N = n; C = c;
for (int i = 0; i < N; i++) { if (i < N - 1) A[i] = l[i]; B[i] = d[i]; }
for (int i = 0; i < N; i++) {
long long S = 0;
for (int j = i + 1; j < N; j++) {
S += 1LL * l[j - 1];
D[i][j] = S; D[j][i] = S;
}
}
long long ans = (1LL << 60);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) ans = min(ans, solve(i, j));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
384 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
384 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
384 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
384 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
384 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
384 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
384 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
384 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
256 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
384 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
384 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
384 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
2 ms |
384 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001 |
17 |
Halted |
0 ms |
0 KB |
- |