#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#include "shortcut.h"
//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
using namespace std;
constexpr static int SPECIAL_CHECK = 80;
constexpr static int MXN = 1e6 + 5;
constexpr static int INF = 1e17;
int pf[MXN];
array<int, 2> jv[MXN];
array<int, 2> iv[MXN];
vector<int> d, l;
int c, n;
static inline int dist(int a, int b)
{
return pf[max(a, b)] - pf[min(a, b)];
}
vector<int> order;
bool check(int k)
{
int xl = -INF, xr = INF, yl = -INF, yr = -INF;
int w = -1;
int mn = INF;
for (int j = 0; j < n; j++) // From left to right
{
if (pf[j] + d[j] - mn > k)
{
xr = min(xr, pf[j] - d[j] + mn + k - c);
yl = max(yl, pf[j] + d[j] - mn - k + c);
}
mn = min(mn, pf[j] - d[j]);
}
int mx = -INF;
for (int i = n-1; i >= 0; i--)
{
if (mx - pf[i] + d[i] > k)
{
xl = max(xl, pf[i] + d[i] + mx - k + c);
if (k == SPECIAL_CHECK)
debug(i, mx);
yr = min(yr, pf[i] - d[i] - mx + k - c);
}
mx = max(mx, pf[i] + d[i]);
}
yr *= -1;
/*
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (dist(i, j) + d[i] + d[j] > k)
{
xl = max(xl, pf[j] + pf[i] - k + c + d[i] + d[j]);
xr = min(xr, pf[j] + pf[i] + k - c - d[i] - d[j]);
yl = max(yl, pf[j] - pf[i] - k + c + d[i] + d[j]);
yr = min(yr, pf[j] - pf[i] + k - c - d[i] - d[j]);
}
}
}
*/
xr++, yr++;
if (k == SPECIAL_CHECK)
debug(xl, xr, yl, yr);
if (xr <= xl || yr <= yl)
return false;
int xs = n, xe = n, ys = 1, ye = 1;
for (int i = 0; i < n; i++)
{
while (xs > 0 && pf[xs-1] + pf[i] >= xl) xs--;
while (xe > 0 && pf[xe-1] + pf[i] >= xr) xe--;
while (ys < n && pf[ys] - pf[i] < yl) ys++;
while (ye < n && pf[ye] - pf[i] < yr) ye++;
if (max(xs, ys) < min(xe, ye))
return true;
}
return false;
}
long long find_shortcut(int32_t _n, vector<int32_t> _l, vector<int32_t> _d, int32_t _c)
{
c = _c;
n = _n;
for (int i : _l)
l.pb(i);
for (int i : _d)
d.pb(i);
for (int i = 1; i <= n; i++)
pf[i] = pf[i-1] + l[i-1];
for (int j = 0; j < n; j++)
jv[j] = {pf[j] + d[j], j};
sort(jv, jv + n);
for (int i = 0; i < n; i++)
iv[i] = {pf[i] - d[i], i};
sort(iv, iv + n);
for (int i = 0; i < n; i++)
debug(iv[i]);
for (int j = 0; j < n; j++)
debug(jv[j]);
int ll = 0, rr = INF;
while (rr - ll > 1)
{
int m = ll+rr>>1;
if (check(m))
rr = m;
else
ll = m;
}
check(SPECIAL_CHECK);
return rr;
}
Compilation message
shortcut.cpp: In function 'bool check(int64_t)':
shortcut.cpp:33:6: warning: unused variable 'w' [-Wunused-variable]
33 | int w = -1;
| ^
shortcut.cpp: In function 'long long int find_shortcut(int32_t, std::vector<int>, std::vector<int>, int32_t)':
shortcut.cpp:115:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
115 | int m = ll+rr>>1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
1 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
0 ms |
212 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |