#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
long long sum[100010];
int idx1,idx2;
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
for(int i=1;i<n;i++)
sum[i] = sum[i-1] + l[i-1];
long long left = 0 , right = 1e18;
long long ans = 0;
long long mx = d[0];
int last = 0 ;
idx1 = 0;
for(int i=1;i<n;i++){
long long dis = sum[i] - sum[last] +d[i] + d[last] ;
if(dis > mx){
mx = dis ;
idx1 = last;
idx2 = i ;
}
if(d[i] > sum[i] - sum[last] + d[last])
last = i ;
}
right = mx;
ans = mx;
while(right >= left){
long long mid=(left+right)/2;
long long mx1 = 0 ;
int idx3 = idx1;
long long mx2= 0;
int idx4 = idx2;
for(int i=idx1+1;i<idx2;i++){
long long dis = sum[i] - sum[idx1] + d[i] + d[idx1];
long long dis2 = sum[idx2] - sum[i] + d[idx2] + d[i];
if(dis > mid){
if(dis2 > mx2)
{
mx2 = dis2 ;
idx4= i ;
}
}
if(dis2 > mid){
if(dis > mx1){
mx1 = dis ;
idx3 = i;
}
}
}
bool can = 1 ;
int idx5 = idx1;
int idx6 = idx2;
long long mn = 1e18;
for(int i=idx1;i<=idx3;i++){
long long dis = max((long long)(sum[i] - sum[idx1] + (long long)d[idx1]),(long long)(sum[idx3] - sum[i] + (long long)d[idx3])) + c + d[idx2];
if(dis > mid)
continue;
long long cur = mid - dis;
int j = lower_bound(sum,sum+n,sum[idx2]-cur) - sum;
if(j < idx4)
j = idx4;
long long dis4 = sum[idx3] - sum[i] + sum[j] - sum[idx4];
if(dis4 < mn){
mn = dis4;
idx5 = i;
idx6 = j;
}
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
long long dis1 = sum[j] - sum[i] + d[i] + d[j] ;
long long dis2 = sum[j] - sum[idx6] ;
if(dis2 < 0)
dis2*=-1;
long long dis3 = sum[i] - sum[idx5] ;
if(dis3 < 0)
dis3*=-1;
long long dis4 = dis2 + dis3 + d[i] + d[j] + c;
long long dis5 = min(dis4,dis1);
if(dis5 > mid)
can = 0 ;
}
}
if(can){
ans = mid;
right = mid - 1;
}
else
left = mid + 1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 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 |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 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 |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 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 |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 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 |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 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 |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 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 |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 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 |
2804 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
2804 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
2804 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
2804 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
2804 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
2804 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
2804 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
2804 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
2804 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
2804 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
2804 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |