#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3000;
const ll INF = 1e18;
ll L[N], R[N], mxL[N], mxR[N], pre[N];
vector<int> d, l;
int n;
ll c;
bool check(ll mid) {
for (int i = 0 ; i < n ; i++) {
if (mxL[i] > mid)
continue;
ll fage3 = -INF;
ll mixer = 0;
for (int j = i + 1 ; j < n ; j++) {
fage3 += l[j - 1];
if (L[j-1] + l[j-1] + d[j] > mid)
fage3 = max(fage3, L[i] + c + d[j]);
if (fage3 > mid)
break;
if (d[j] + l[j] + R[j + 1] > mid) {
mixer = max(mixer, pre[j] - pre[i] + d[j] + c);
}
if (mxR[j] <= mid) {
if (L[i] + min(pre[j] - pre[i], c) + R[j] <= mid) {
if ((fage3 - L[i] + (mixer-c)) <= mid) {
if (mixer + R[j] <= mid) {
return 1;
}
}
}
}
}
}
return false;
}
ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
if (n > 3000)
return -1;
::n = n;
::d = d;
::c = c;
::l = l;
for (int i = 0; i < n; ++i) {
L[i] = d[i];
if (i)
pre[i] = l[i - 1] + pre[i - 1];
if (i)
L[i] = max(L[i - 1] + l[i - 1], L[i]);
mxL[i] = max(i ? mxL[i - 1] : 0, d[i] + (i ? L[i - 1] + l[i - 1] : 0));
}
for (int i = n - 1 ; i >= 0 ; i--) {
R[i] = d[i];
if (i != n - 1)
R[i] = max(R[i], R[i + 1] + l[i]);
mxR[i] = max(i != n - 1 ? mxR[i + 1] : 0, d[i] + (i != n - 1 ? R[i + 1] + l[i] : 0));
}
ll lo = *max_element(d.begin(), d.end()) , hi = 1e9 * (N + 3), best = -1;
while (lo <= hi) {
ll mid = (lo + hi) / 2;
if (check(mid)) {
best = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
assert(best != -1);
return best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2140 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2140 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2140 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2140 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2140 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2140 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2140 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2140 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2140 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2140 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2140 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |