# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867903 | Lib | Shortcut (IOI16_shortcut) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "shortcut.h"
using namespace std;
long long lim=1000000000000000000;
long long BoundTopLeft,BoundTopRight,BoundBottomLeft,BoundBottomRight; //Where the lines that forms the current bound cuts the X-axis
long long TopLeft,TopRight,BottomLeft,BottomRight; //Where the lines that forms the current square cuts the Y-axis
int n;
long long Mainline[1000003];
long long Secondline[1000003];
long long PrefixMax[1000003];
long long PrefixMaxpos[1000003];
long long Extraline;
long long C,X,Y;
long long cntok;
long long PossibleDiameter(long long Dist){
//Dist=8;
BoundTopLeft=-lim;
BoundTopRight=lim;
BoundBottomLeft=-lim;
BoundBottomRight=lim;
cntok=0;
for(int k=1;k<n;k++){
for(int i=k+1;i<=n;i++){
C=Dist-(Extraline+Secondline[i]+Secondline[k]);
X=Mainline[i];
Y=Mainline[k];
TopLeft=X-C-Y;
TopRight=X+C+Y;
BottomLeft=X-C+Y;
BottomRight=X+C-Y;
if((Secondline[i]+Secondline[k]+Mainline[i]-Mainline[k])>Dist){
BoundTopLeft=max(BoundTopLeft,TopLeft);
BoundTopRight=min(BoundTopRight,TopRight);
BoundBottomRight=min(BoundBottomRight,BottomRight);
BoundBottomLeft=max(BoundBottomLeft,BottomLeft);
}
}
}
if(BoundTopLeft>BoundBottomRight||BoundBottomLeft>BoundTopRight){
return 0;
}
for(int k=1;k<n;k++){
for(int l=k+1;l<=n;l++){
if((BoundTopLeft <= Mainline[l]-Mainline[k])&&(Mainline[l]-Mainline[k] <= BoundBottomRight)&&(BoundBottomLeft <= Mainline[k]+Mainline[l])&&(Mainline[k]+Mainline[l] <= BoundTopRight)){
return 1;
}
if((Secondline[l]+Secondline[k]+Mainline[l]-Mainline[k])>Dist){
}else{
cntok++;
}
}
}
if(cntok==n*(n-1)/2){
return 1;
}
return 0;
}
long long find_shortcut(int N, vector <int> l, vector<int> d, int c){
long long temp=0;
n=N;
for(int i=2;i<=n;i++){
temp=l[i-2];
Mainline[i]=Mainline[i-1]+temp;
}
for(int i=1;i<=n;i++){
Secondline[i]=d[i-1];
}
Extraline=c;
long long l=1,r=lim;
long long mid;
while(r-l>=1){
mid=(r+l)/2;
if(PossibleDiameter(mid)){
r=mid;
}else{
l=mid+1;
}
}
if(PossibleDiameter(l)){
return l;
}else if(PossibleDiameter(r)){
return r;
}
}