#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
int dfs(int n, vector<vector<pii>> &g, int v, int p) {
int ans = 0;
for (auto [u, du] : g[v]) {
if (u != p) {
ans = max(ans, dfs(u, g, u, v) + du);
}
}
return ans;
}
int diam(int n, vector<signed> l, vector<signed> d) {
vector<vector<pii>> g(2 * n);
for (int i = 0; i < n - 1; i++) {
g[i].push_back({i + 1, l[i]});
g[i + 1].push_back({i, l[i]});
}
for (int i = 0; i < n; i++) {
g[i].push_back({n + i, d[i]});
g[n + i].push_back({i, d[i]});
}
int ans = 0;
for (int i = 0; i < 2 * n; i++) ans = max(ans, dfs(n, g, i, i));
return ans;
}
int find_shortcut(signed n, vector<signed> l, vector<signed> d, signed c) {
int noshort = diam(n, l, d);
int ll = 0, rr = 1e17;
while (rr - ll > 1) {
int mm = (ll + rr) / 2;
int Xmn = -1e17, Ymn = -1e17, Xmx = 1e17, Ymx = 1e17; // X = y + z, Y = y - z
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int goal = mm - c - d[i] - d[j];
int zavg = l[j], ymin = l[i] - goal, ymax = l[i] + goal;
Xmn = max(Xmn, ymin + zavg);
Xmx = min(Xmx, ymax + zavg);
Ymn = max(Ymn, ymin - zavg);
Ymx = min(Ymx, ymax - zavg);
}
}
bool ok = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int X = l[i] + l[j], Y = l[i] - l[j];
ok = ok || (Xmn <= X && X <= Xmx && Ymn <= Y && Y <= Ymx);
}
}
if (ok) rr = mm;
else ll = mm;
}
return min(rr, noshort);
}
#ifdef LOCAL
signed main() {
cout << find_shortcut(4, {10, 20, 20}, {0, 40, 0, 30}, 10) << "\n";
cout << find_shortcut(9, {10, 10, 10, 10, 10, 10, 10, 10}, {20, 0, 30, 0, 0, 40, 0, 40, 0}, 30) << "\n";
cout << find_shortcut(4, {2, 2, 2}, {1, 10, 10, 1}, 1) << "\n";
cout << find_shortcut(3, {1, 1}, {1, 1, 1}, 3) << "\n";
cout << find_shortcut(2, {10}, {1, 1}, 1) << "\n";
}
#endif
Compilation message
shortcut.cpp: In function 'long long int dfs(long long int, std::vector<std::vector<std::pair<long long int, long long int> > >&, long long int, long long int)':
shortcut.cpp:10:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
10 | for (auto [u, du] : g[v]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
348 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
344 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 3000000001 |
13 |
Halted |
0 ms |
0 KB |
- |