qwq,写的凸包,三个hack数据一个没过,其他的都过了。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+7;
struct Node
{
int x,y;
bool operator != (Node a)
{
if(a.x==x&&a.y==y) return 0;
return 1;
}
bool operator == (Node a)
{
if(a.x==x&&a.y==y) return 1;
return 0;
}
}a[N],st[N];
int top,k;
inline int Dis(Node A,Node B)
{
int ans=(B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y);
return (ans);
}
inline int check(Node A1,Node A2,Node B1,Node B2)
{
return (A2.x-A1.x)*(B2.y-B1.y)-(B2.x-B1.x)*(A2.y-A1.y);
}
inline int check2(Node A1,Node A2,Node B1,Node B2)
{
int ans1=check(A1,A2,B1,B2);
if(ans1==0)
return Dis(A1,A2)-Dis(B1,B2);
return ans1;
}
int n;
long double ans;
inline bool cmp(Node A,Node B)
{
int pd=check(a[1],A,a[1],B);
if(pd>0)
return 1;
if(pd==0&&Dis(a[0],A)<Dis(a[0],B))
return 1;
return 0;
}
inline long double S(Node A,Node B,Node C)
{
long double AA=(long double)sqrt(Dis(A,B));
long double BB=(long double)sqrt(Dis(A,C));
long double CC=(long double)sqrt(Dis(B,C));
long double PP=(long double)(AA+BB+CC)/2.0;
return (long double)sqrt((long double)PP*(long double)(PP-AA)*(long double)(PP-BB)*(long double)(PP-CC));
}
inline void del(int x)
{
for(int i=1;i<=n;i++)
{
if(a[i]==st[x])
{
for(int j=i+1;j<=n;j++)
{
a[j-1]=a[j];
}
a[n]={0,0};
n--;
return;
}
}
}
priority_queue<int,vector<int>,greater<int> > q;
signed main()
{
scanf("%lld %lld",&n,&k);
for(int i=1;i<=n;i++)
scanf("%lld %lld",&a[i].x,&a[i].y);
for(int cs=1;cs<=k;cs++)
{
top=0;
memset(st,0,sizeof(st));
for(int i=1;i<=n;i++)
{
if(i!=1&&(a[i].y<a[1].y||(a[i].y==a[1].y&&a[i].x<a[1].x)))
{
Node s=a[1];
a[1]=a[i];
a[i]=s;
}
}
sort(a+2,a+1+n,cmp);
st[++top]=a[1];
for(int i=2;i<=n;i++)
{
while(top>1&&check2(st[top-1],st[top],st[top],a[i])<=0)
top--;
st[++top]=a[i];
}
st[top+1]=a[1];
int j=2;
int ans=0;
int id1=-1,id2=-1;
if(top==2)
{
id1=1;
id2=2;
ans=Dis(st[1],st[2]);
}
for(int i=1;i<=top;i++)
{
ans=max(ans,Dis(st[i],st[i+1]));
while((long double)S(st[i],st[i+1],st[j])<(long double)S(st[i],st[i+1],st[j+1]))
{
j++;
if(j>top)
j=1;
}
int v1=Dis(st[i],st[j]),v2=Dis(st[i+1],st[j]);
if(v1>ans)
{
ans=v1,id1=i,id2=j;
}
if(v2>ans)
{
ans=v2,id1=i+1,id2=j;
}
ans=max(ans,max(v1,v2));
}
q.push(ans);
if(q.size()>k) q.pop();
for(int i=1;i<=n;i++)
{
if(a[i]!=st[id1]&&a[i]!=st[id2])
{
q.push(Dis(a[i],st[id1]));
}
if(q.size()>k) q.pop();
}
for(int i=1;i<=n;i++)
{
if(a[i]!=st[id1]&&a[i]!=st[id2])
q.push(Dis(a[i],st[id2]));
if(q.size()>k) q.pop();
}
del(id1);
del(id2);
}
printf("%lld\n",q.top());
}