CHEFSQUA-Editorial

Yes, even i just pulled up a random AC answer and was wrong with the same kind of test case.

It was clearly mentioned that the square need not have its sides parallel to the X and Y axes. Your two assumptions would be always true only if the square had sides parallel to the X and Y axes.
example -
(1,1) (3,5) and (-1,7) and (-3,3) form a square. So here your second point fails that 1,1 and 3,5 should necessarily be on the diagonal as they dont form a side parallel to the axes.

@admin​:diamonds::diamonds: Please update tester and setter’s solution.

My code is giving right answer for all possible cases. Still here it saying wrong answer. Please tll me why. my code is here. http://ideone.com/QYh1da

#include <stdio.h>
#include <stdlib.h>
void quick_sort(long long int arr[],long long int y[],int low,int high)
{
int pivot,j,i;
long long int temp;
if(low<high)
{
pivot = low;
i = low;
j = high;

while(i<j)
{
while((arr[i]<=arr[pivot])&&(i<high))
{
i++;
}

while(arr[j]>arr[pivot])
{
j–;
}

if(i<j)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
temp=y[i];
y[i]=y[j];
y[j]=temp;
}
}

temp=arr[pivot];
arr[pivot]=arr[j];
arr[j]=temp;
temp=y[pivot];
y[pivot]=y[j];
y[j]=temp;
quick_sort(arr,y,low,j-1);
quick_sort(arr,y,j+1,high);
}
}
int find(long long int a[],int e,long long int m){
int l=0,u=e,c=-1;
while(l<=u){
int mid=(l+u)/2;
if(m==a[mid]){
if(mid==0){c=0;break;}
else if(a[mid-1]<m){c=mid;break;}
else u=mid-1;
}
else if(m<a[mid]){
u=mid-1;
}
else
l=mid+1;
}
// printf("( %lld %d) \n",m,c);
return c;
}
int main(void) {
int n;
scanf("%d",&n);
if(n<3){
printf("%d\n",4-n);
return 0;
}
long long int x[n],y[n];
int i,j;
for(i=0;i<n;i++){
scanf("%lld %lld",&x[i],&y[i]);
// printf(" %lld %lld",x[i],y[i]);
}
// printf("\n");
quick_sort(x,y,0,n-1);
/* for(i=0;i<n;i++){
printf(" %lld %lld",x[i],y[i]);
} */
// printf("\n");
int f1=-1,f4=-1,min=n,cnt=0,f2=0,f3=0;
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
long long int x1=x[i]-(y[j]-y[i]);
long long int y1=y[i]-(x[i]-x[j]);
long long int x4=x[j]-(y[j]-y[i]);
long long int y4=y[j]-(x[i]-x[j]);
f1=find(x,n-1,x1);
f4=find(x,n-1,x4);
// printf("(%lld %lld %lld) (%lld %lld %d) \n",x1,y1,y[f1],x4,y4,y[f4]);
if((f1>=0)&&(y[f1]==y1))f2=1;
else if(f1>=0){
int id=f1;
while(x[id]==x1){
if(y[id]==y1){f2=1;break;}
id++;
}
}
else f2=0;
//if(f2)printf("%lld %lld %lld %lld \n",x[i],y[i],x1,y1);
if((f4>=0)&&(y[f4]==y4))f3=1;
else if(f4>=0){
int id=f4;
while(x[id]==x1){
if(y[id]==y1){f3=1;break;}
id++;
}
}
else f3=0;
// if(f2)printf("%lld %lld %lld %lld \n",x[j],y[j],x4,y4);
if(f2&&f3){min=0;break;}
else if((f2&&!(f3))||(f3&&!(f2))){cnt=1;}
else{cnt=2;}
if(cnt<min)min=cnt;
}
if(f2&&f3)break;
}
printf("%d\n",min);
return 0;
}

My ACed solution gives 0. By the way you can report this as feedback to codechef.
http://www.codechef.com/viewsolution/5142562

@pranjalranjan yes :stuck_out_tongue:

@shiva1k95_10 you’ve used so much of if-else statements then it might give TLE for some big value of N say 2000. Use random cases to check this. An use switch for faster evaluation.

@kihsuak did you check your solve1 and solve functions, I think they’re not completely correct.

Thats the bad thing…i reported it…and still stronger test cases were not added!

if you’re asking how to get the other 2 points, regardless that the problem is not even asking for it, then treat the 2 points as a line segment then rotate it 90 degrees along the midpoint of the line. you can rotate either the line or just the points.

When 3 or more points are given, for every 2 points shouldn’t we also consider the square with these points as the diagonal ? So shouldn’t 3 squares be checked ?
Or does considering the 2 squares include this square as well ? I’m confused

if set has only 2 points then too it is not possible to construct a square of these points by adding 2 other points. for eg. {(0,0), (1,3)} is given set of points. the answer should be 2(as deducted from the logic in above post) but it can be seen that answer is 3.