#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#include "shortcut.h"
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
#define ll long long
const int N = 3005;
ll v1[N][N], v2[N][N], v3[N][N], v4[N][N], mn2[N][N], mn3[N][N];
ll find_shortcut(int n, vector<int> l, vector<int> a, int c) {
reverse(l.begin(), l.end()), l.push_back(0), reverse(l.begin(), l.end()), l.push_back(0);
reverse(a.begin(), a.end()), a.push_back(-1), reverse(a.begin(), a.end());
ll prf[n + 2]{};
for (int i = 2; i <= n; i++) {
prf[i] = prf[i - 1] + l[i - 1];
}
ll prfmx[n + 2]{}, prfd[n + 2]{}, sufmx[n + 2]{}, sufd[n + 2]{};
for (int i = 1; i <= n; i++) {
prfmx[i] = max(prfmx[i - 1] + l[i - 1], (ll)a[i]);
prfd[i] = max(prfd[i - 1], prfmx[i - 1] + l[i - 1] + a[i]);
}
for (int i = n; i >= 1; i--) {
sufmx[i] = max(sufmx[i + 1] + l[i], (ll)a[i]);
sufd[i] = max(sufd[i + 1], sufmx[i + 1] + l[i] + a[i]);
}
auto check = [&] (ll t) {
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (prf[j] - prf[i] + a[i] + a[j] <= t) {
v1[i][j] = v2[i][j] = v3[i][j] = v4[i][j] = 1e18;
continue;
}
v1[i][j] = prf[j] - prf[i] - a[i] - a[j];
v2[i][j] = - prf[j] + prf[i] - a[i] - a[j];
v3[i][j] = prf[i] + prf[j] - a[i] - a[j];
v4[i][j] = - prf[i] - prf[j] - a[i] - a[j];
}
}
for (int x = 1; x <= n; x++) {
for (int y = x + 1; y <= n; y++) {
mn2[x][y] = mn3[x][y] = 1e18;
}
}
for (int y = 2; y <= n; y++) {
for (int i = 1; i < y; i++) {
if (i - 1 >= 1) {
v3[i][y] = min(v3[i][y], v3[i - 1][y]);
v2[i][y] = min(v2[i][y], v2[i - 1][y]);
}
}
}
for (int x = 1; x <= n; x++) {
for (int i = n; i >= 1; i--) {
if (i + 1 <= n) {
v4[x][i] = min(v4[x][i], v4[x][i + 1]);
}
}
ll mn = 1e18, mn_ = 1e18;
for (int y = x + 1; y <= n; y++) {
mn_ = min(mn_, v3[x][y]);
mn3[x][y] = mn_;
}
mn = mn_ = 1e18;
for (int y = n; y >= x + 1; y--) {
mn = min(mn, v2[x][y]);
mn2[x][y] = mn;
}
}
for (int y = 2; y <= n; y++) {
ll mn1 = 1e18;
ll mn4 = 1e18;
for (int x = y - 1; x >= 1; x--) {
v1[x][x + 1] = min(v1[x][x + 1], v1[x][y]);
mn1 = min(mn1, v1[x][x + 1]);
mn4 = min(mn4, v4[x][y]);
ll len = prf[y] - prf[x] + c;
if (prfd[x] <= t && sufd[y] <= t && len - mn1 <= t && -(prf[y] - prf[x]) + c - mn2[x][y] <= t && len + 2 * prf[x] - mn3[x][y] <= t && len - 2 * prf[y] - mn4 <= t) {
return 1;
}
}
}
return 0;
};
ll s = 0, e = 1e9;
while (s <= e) {
ll md = (s + e) >> 1;
if (check(md)) {
e = md - 1;
} else {
s = md + 1;
}
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
12792 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
10588 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
10588 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
10588 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
10588 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
10588 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
10588 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
1 ms |
10588 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000001 |
11 |
Halted |
0 ms |
0 KB |
- |