#include <bits/stdc++.h>
#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];
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];
}
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] = t + prf[j] - prf[i] - a[i] - a[j];
v2[i][j] = t - prf[j] + prf[i] - a[i] - a[j];
v3[i][j] = t + prf[i] + prf[j] - a[i] - a[j];
v4[i][j] = t - prf[i] - prf[j] - a[i] - a[j];
}
}
for (int x = 1; x <= n; x++) {
for (int y = x + 1; y <= n; y++) {
ll mn1 = 1e18, mn2 = 1e18, mn3 = 1e18, mn4 = 1e18;
ll len = prf[y] - prf[x] + c;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (x <= i && j <= y) {
mn1 = min(mn1, v1[i][j]);
} else if (i < x && y < j) {
mn2 = min(mn2, v2[i][j]);
} else if (i <= x && x <= j && j <= y) {
mn3 = min(mn3, v3[i][j]);
} else if (x <= i && i <= y && y <= j) {
mn4 = min(mn4, v4[i][j]);
}
}
}
if (len <= mn1 && -(prf[y] - prf[x]) + c <= mn2 && len + 2 * prf[x] <= mn3 && len - 2 * prf[y] <= mn4) {
return 1;
}
}
}
return 0;
};
ll s = 0, e = 1ll << 42;
while (s <= e) {
ll md = (s + e) >> 1;
if (check(md)) {
e = md - 1;
} else {
s = md + 1;
}
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
8540 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
6492 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
6492 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
7000 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
6488 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
6492 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
6492 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
6492 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
6748 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
6488 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
6492 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
6584 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
8540 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
8792 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
8540 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
6492 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
6492 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
6492 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
1 ms |
8540 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |