#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
vector<ll> x(n);
for(int i=0; i+1<n; ++i)
x[i+1]=x[i]+l[i];
ll lb=1, rb=2e15;
while(lb<rb) {
ll mb=(lb+rb)/2, a1=-1e18, a2=-1e18, a3=-1e18, b1=-1e18, b2=1e18, b3=-1e18, b4=1e18;
vector<int> e{n-1};
for(int i=n-2; ~i; --i)
if(d[i]-x[i]>d[e.back()]-x[e.back()])
e.push_back(i);
for(int i=e.size()-1, j=0; j<n; ++j) {
if(d[j]+x[j]<a1)
continue;
a1=d[j]+x[j];
for(; ~i&&d[e[i]]-x[e[i]]>mb-a1; --i) {
if(e[i]==j) {
for(int k=i+1<e.size()?e[i+1]:0; k<j; ++k) {
a2=max(d[k]+x[k], a2);
a3=max(d[k]-x[k], a3);
}
break;
} else {
a2=max(d[e[i]]+x[e[i]], a2);
a3=max(d[e[i]]-x[e[i]], a3);
}
}
b1=max(c-mb+d[j]+x[j]+a2, b1);
b2=min(mb-c-d[j]+x[j]-a3, b2);
b3=max(c-mb+d[j]-x[j]+a2, b3);
b4=min(mb-c-d[j]-x[j]-a3, b4);
}
bool ok=0;
for(int i=0, j1=n, j2=n, j3=0, j4=0; i<n; ++i) {
for(; j1&&x[j1-1]>=b1-x[i]; --j1);
for(; j2&&x[j2-1]>b2-x[i]; --j2);
for(; j3<n&&x[j3]<b3+x[i]; ++j3);
for(; j4<n&&x[j4]<=b4+x[i]; ++j4);
ok|=max(j1, j3)<min(j2, j4);
}
if(ok)
rb=mb;
else
lb=mb+1;
}
return lb;
}
Compilation message
shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int k=i+1<e.size()?e[i+1]:0; k<j; ++k) {
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
256 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
256 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
256 KB |
n = 2, incorrect answer: jury 62 vs contestant 1 |
6 |
Halted |
0 ms |
0 KB |
- |