#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pl pair<ll,ll>
#define x first
#define y second
const ll N=2e5+69420;
pl f[N],s[N],inc[N];
ll n,r,dif[N];
bool check(int i,int p)
{
ll fx=(f[i].x+inc[i].x*p);
ll fy=(f[i].y+inc[i].y*p);
return (fx*fx+fy*fy)<=(r*r);
}
void solve()
{
cin>>n>>r;
bool pos=1;
for(int i=1;i<=n;i++)
{
cin>>f[i].x>>f[i].y>>s[i].x>>s[i].y;
inc[i].x=(s[i].x-f[i].x);
inc[i].y=(s[i].y-f[i].y);
pos&=(inc[i].y==0);
}
if(pos)
{
for(int i=1;i<=n;i++)
{
if(check(i,0))
{
dif[0]++;
dif[1]--;
}
ll xc=r*r - f[i].y*f[i].y;
if(xc<0)continue;
ld px=(ld)sqrtl(xc);
// find t such that
//0<=t and t<=2e4
// both inc[i].y and inc[i].x can't be zero
ll ed=(px-f[i].x)/inc[i].x;
ll st=max((ld)1.0,(-px-f[i].x+inc[i].x-1)/inc[i].x);
if(inc[i].x<0)
{
// inc[i].x*=-1;
ed=(-px-f[i].x)/inc[i].x;
st=max((ld)1.0,(px-f[i].x+inc[i].x-1)/inc[i].x);
// inc[i].x*=-1;
}
// st=max(st,1ll);
if(st<=ed)
{
// cout<<"Range "<<st<<' '<<ed<<endl;
// cout<<px<<' '<<f[i].x<<' '<<inc[i].x<<endl;
dif[st]++;
dif[ed+1]--;
}
// t >= (-px-f[i].x)/ inc[i].x
}
int as=0;
int ans=0;
for(int i=0;i<N;i++)
{
ans+=dif[i];
as=max(ans,as);
}
cout<<as<<endl;
}
else
{
int as=0;
for(int p=0;p<=2e4;p++)
{
int ans=0;
for(int i=1;i<=n;i++)
{
ans+=check(i,p);
}
as=max(as,ans);
}
cout<<as<<endl;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |