Submission #867903

# Submission time Handle Problem Language Result Execution time Memory
867903 2023-10-29T17:22:50 Z Lib Shortcut (IOI16_shortcut) C++14
Compilation error
0 ms 0 KB
#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;
	}
}

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:71:12: error: declaration of 'long long int l' shadows a parameter
   71 |  long long l=1,r=lim;
      |            ^
shortcut.cpp:60:45: note: 'std::vector<int> l' previously declared here
   60 | long long find_shortcut(int N, vector <int> l, vector<int> d, int c){
      |                                ~~~~~~~~~~~~~^
shortcut.cpp:86:1: warning: control reaches end of non-void function [-Wreturn-type]
   86 | }
      | ^