#include "shortcut.h"
#include <bits/stdc++.h>
#define N 1000005
using namespace std;
long long p[N];
long long d[N];
int n,nwedge;
bool ck(long long k){
long long xl = -1e18, xr = 1e18;
long long yl = -1e18, yr = 1e18;
for(int i = 0;i<n;i++){
for(int j = i;j<n;j++){
if(-p[i] + d[i] + p[j] + d[j] > k){
xl = max(xl,p[i] + p[j] - (k - d[i] - d[j] - nwedge));
xr = min(xr,p[i] + p[j] + (k - d[i] - d[j] - nwedge));
yl = min(xr,p[i] - p[j] - (k - d[i] - d[j] - nwedge));
yr = max(xr,p[i] - p[j] + (k - d[i] - d[j] - nwedge));
}
}
}
// cout << k << endl;
// for(int i = 0;i<n;i++){
// cout << p[i] << " ";
// }
// cout << endl;
// cout << xl << " " << xr << " " << yl << " " << yr << endl;
if(xl > xr || yl > yr)return 0;
int pt1 = n,pt2 = n-1;
int pt3 = -1,pt4 = 0;
for(int i = 0;i<n;i++){
while(pt1 && p[pt1-1] + p[i] >= xl){
pt1--;
}
while(pt2 && p[pt2] + p[i] > xr){
pt2--;
}
while(pt3 + 1 != n && -p[pt3+1] + p[i] >= yl){
pt3++;
}
while(pt4 != n && -p[pt4] + p[i] > yr){
pt4++;
}
int l1 = pt1,r1 = pt2;
int l2 = pt4,r2 = pt3;
if(r1 < l1 || r2 < l2)continue;
if(r1 < l2 || r2 < l1)continue;
return 1;
}
return 0;
}
long long find_shortcut(int n_, vector<int> l_, vector<int> d_, int nwedge_)
{
n = n_;
nwedge = nwedge_;
for(int i = 1;i<n;i++){
p[i] = p[i-1] + l_[i-1];
}
for(int i = 0;i<n;i++){
d[i] = d_[i];
}
long long l = 0, r = 1e18;
while(l < r){
long long m = (l + r)/2;
if(ck(m)){
r = m;
}
else l = m+1;
}
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
212 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |