#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
struct star{
ll xx,yy,dx,dy;
}input[30010];
ll n,maxday,top;
struct nowstar{
ll x, y;
}now[30010],st[30010];
ll cross(ll a, ll b, ll c, ll d)
{
return (ll)((ll)a*d-(ll)b*c);
}
bool ccmp(nowstar A, nowstar B)
{
if(A.x==B.x) return A.y<B.y;
return A.x<B.x;
}
bool rcmp(nowstar A, nowstar B)
{
return cross(A.x-now[1].x,A.y-now[1].y,B.x-now[1].x,B.y-now[1].y)>0;
}
ll f(ll x){return abs(((x-1)%top)+1);}
ll dist(nowstar A, nowstar B)
{
return ((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y));
}
ll maxdis(ll day)
{
ll i,j;
top=0;
for(i=1;i<=n;i++)
{
now[i].x=input[i].xx+input[i].dx*day;
now[i].y=input[i].yy+input[i].dy*day;
}
sort(now+1,now+n+1,ccmp);
sort(now+2,now+n+1,rcmp);
st[++top]=now[1];
st[++top]=now[2];
for(i=3;i<=n;i++)
{
while(top>=2&&cross(st[top].x-st[top-1].x,st[top].y-st[top-1].y,now[i].x-st[top].x,now[i].y-st[top].y)<=0) top--;
st[++top]=now[i];
}
ll ret=0;
if(top==1||top==0) return 0;
if(top==2) return dist(st[1],st[2]);
for(i=1,j=2;i<=top;i++)
{
while(cross(st[f(i+1)].x-st[f(i)].x,st[f(i+1)].y-st[f(i)].y,st[f(j+1)].x-st[f(j)].x,st[f(j+1)].y-st[f(j)].y)>0)j++;
ret=max(ret,dist(st[f(i)],st[f(j)]));
ret=max(ret,dist(st[f(i)],st[f(j+1)]));
}
return ret;
}
int main()
{
ll i;
scanf("%lld %lld",&n, &maxday);
for(i=1;i<=n;i++)
{
scanf("%lld %lld %lld %lld", &input[i].xx, &input[i].yy, &input[i].dx, &input[i].dy);
}
ll l=0, r=maxday, x1, x2,ci=50;
while(ci--&&l+1<r)
{
x1=((ll)2*l+r)/3;
x2=((ll)2*r+l)/3;
if(maxdis(x1)>maxdis(x2)) l=x1;
else r=x2;
}
ll ans1=maxdis(l),ans2=l;
for(i=l+1;i<=r;i++)
{
if(maxdis(i)<ans1)
{
ans1=maxdis(i);
ans2=i;
}
}
printf("%lld\n%lld", ans2,ans1);
}
Compilation message
dist.cpp: In function 'int main()':
dist.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&n, &maxday);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dist.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld", &input[i].xx, &input[i].yy, &input[i].dx, &input[i].dy);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
528 KB |
Output is correct |
4 |
Correct |
2 ms |
528 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
528 KB |
Output is correct |
4 |
Correct |
2 ms |
528 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
612 KB |
Output is correct |
11 |
Correct |
22 ms |
628 KB |
Output is correct |
12 |
Correct |
25 ms |
652 KB |
Output is correct |
13 |
Correct |
15 ms |
676 KB |
Output is correct |
14 |
Correct |
22 ms |
824 KB |
Output is correct |
15 |
Incorrect |
17 ms |
824 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
883 ms |
2816 KB |
Output is correct |
2 |
Correct |
910 ms |
3340 KB |
Output is correct |
3 |
Correct |
814 ms |
4004 KB |
Output is correct |
4 |
Correct |
155 ms |
5196 KB |
Output is correct |
5 |
Incorrect |
88 ms |
5204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
528 KB |
Output is correct |
4 |
Correct |
2 ms |
528 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
612 KB |
Output is correct |
11 |
Correct |
22 ms |
628 KB |
Output is correct |
12 |
Correct |
25 ms |
652 KB |
Output is correct |
13 |
Correct |
15 ms |
676 KB |
Output is correct |
14 |
Correct |
22 ms |
824 KB |
Output is correct |
15 |
Incorrect |
17 ms |
824 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |