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>
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PB push_back
#define F first
#define S second
const int INF=1e9;
const long long LINF=1e18;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
const int MX=1e8, N=30000;
int n, r;
vector<pair<pii, pii>> inf;
bool chk(int x, int y)
{
x=abs(x); y=abs(y);
if(x==r && y==0) return true;
if(y==r && x==0) return true;
if(x==0 && y==0) return true;
if(x>=0 && x<=r-1 && y>=0 && y<=r-1) return true;
else return false;
}
bool inside(int x, int y, int ax, int ay)
{
return chk(x, y)||chk(x-ax, y-ay);
}
bool passed(int x, int y, int nx, int ny)
{
bool left=false, right=false;
if(x<=0){
if(nx>=0) left=true;
}
else if(x>=0){
if(nx<=0) left=true;
}
if(y<=0){
if(ny>=0) right=true;
}
else if(y>=0){
if(ny<=0) right=true;
}
return left&&right;
}
bool good(int i)
{
int x=inf[i].F.F, y=inf[i].F.S, z=inf[i].S.F, w=inf[i].S.S;
int ax=z-x, ay=w-y;
//TODO MAKE HIGHER
int l=0, r=N;
while(l<r){
int m=(l+r)/2;
int nx=x+ax*m, ny=y+ay*m;
if(nx<-10000 || nx>10000 || ny<-10000 || ny>10000) r=m;
if(passed(x, y, nx, ny)) r=m;
else l=m+1;
}
int nx=x+l*ax, ny=y+l*ay;
if(inside(nx, ny, ax, ay)){
return true;
}
else{
return false;
}
}
int times[N];
void pre(int i)
{
int x=inf[i].F.F, y=inf[i].F.S, z=inf[i].S.F, w=inf[i].S.S;
int ax=z-x, ay=w-y;
//TODO MAKE HIGHER
int l=0, r=N;
while(l<r){
int m=(l+r)/2;
int nx=x+ax*m, ny=y+ay*m;
if(nx<-10000 || nx>10000 || ny<-10000 || ny>10000) r=m;
if(passed(x, y, nx, ny)||chk(nx, ny)) r=m;
else{
l=m+1;
//cout << nx << " " << ny << '\n';
}
}
times[l]++;
//cout << l << " ";
//TODO MAKE HIGHER
l=0, r=N;
while(l<r){
int m=(l+r)/2;
int nx=x+ax*m, ny=y+ay*m;
if(nx<-10000 || nx>10000 || ny<-10000 || ny>10000) r=m;
if(passed(x, y, nx, ny) && !chk(nx, ny)) r=m;
else{
l=m+1;
//cout << nx << " " << ny << '\n';
}
}
times[l]--;
//cout << l << '\n';
}
int main()
{
FAST_IO;
cin >> n >> r;
vi ar;
FOR(i, 0, n)
{
int x, y, z, w;
cin >> x >> y >> z >> w;
inf.PB({{x, y}, {z, w}});
if(inside(x, y, z-x, w-y)||good(i)){
ar.PB(i);
}
}
for(auto x : ar){
pre(x);
}
int tot=0, mx=0;
FOR(i, 0, N)
{
tot+=times[i];
mx=max(mx, tot);
}
cout << mx;
}
# | 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... |