답안 #113208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113208 2019-05-24T10:43:46 Z knon0501 먼 별 (KOI16_dist) C++14
0 / 100
101 ms 2976 KB
#include <bits/stdc++.h>
using namespace std;
int n,t;
#define x first
#define y second
typedef long long ll;
typedef pair<ll,ll> pp;
pp a[300005];
pp v[300005];
pp s[300005];
pp b[300005];
ll ans=8e18+2e17;
int tt;
long double f(pp q,pp w,pp e){
    ll aa=q.y-w.y;
    ll bb=w.x-q.x;
    ll cc=q.x*w.y-q.y*w.x;
    return (long double)(aa*e.x+bb*e.y+cc)/sqrt((long double)(aa*aa+bb*bb));
}
ll ccw(pp q,pp w,pp e){
    return (w.x-q.x)*(e.y-w.y)-(w.y-q.y)*(e.x-w.x);
}
ll dist(pp q,pp w){
    return (w.x-q.x)*(w.x-q.x)+(w.y-q.y)*(w.y-q.y);
}
bool comp(pp q,pp w){
    ll k=ccw(b[1],q,w);
    return k ? k>0 : dist(b[1],q)<dist(b[1],w);
}
ll process(ll ti){
    if(ti<0 || ti>t)return 1e18;
    int i,j;
    ll ret=0;
    for(i=1 ; i<=n ; i++)b[i]={a[i].x+ti*v[i].x,a[i].y+ti*v[i].y};
    sort(b+1,b+n+1);
    sort(b+2,b+n+1,comp);
    ret=dist(b[1],b[n]);
    int to=2;
    s[1]=b[1];
    s[2]=b[2];
    b[n+1]=b[1];
    for(i=3 ; i<=n+1 ; i++){
        while(to>=2 && ccw(s[to-1],s[to],b[i])<=0)to--;
        s[++to]=b[i];
    }
    to--;
    if(to<3)return ret;
   /// cout<<to<<" "<<ti<<endl;
    j=2;
    for(i=1 ; i<=to ; i++){
        int ii=i%to+1;
        if(j>to)j=1;
        while(f(s[i],s[ii],s[j%to+1])>f(s[i],s[ii],s[j]) ){
            ret=max({ret,dist(s[i],s[j]),dist(s[ii],s[j])});
            j++;
            if(j>to)j=1;
        }
        ret=max({ret,dist(s[i],s[j]),dist(s[ii],s[j])});
    }
   /// cout<<ret<<endl;
    return ret;
}
int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);

    cin>>n>>t;
 
    int i;
    for(i=1 ; i<=n ; i++)cin>>a[i].x>>a[i].y>>v[i].x>>v[i].y;

    int lef=0;
    int rig=t;

    while(rig>=lef){
        int mid=(lef+rig)/2;
        ll q=process(mid-1);
        ll w=process(mid);
        ll e=process(mid+1);
        if(q<ans){
            ans=q;
            tt=mid-1;
        }
        if(w<ans){
            ans=w;
            tt=mid;
        }
        if(e<ans){
            ans=e;
            tt=mid+1;
        }
        if(q>w && w>e)lef=mid+1;
        else rig=mid-1;
    }
    cout<<tt<<endl<<ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 2568 KB Output is correct
2 Correct 80 ms 2348 KB Output is correct
3 Correct 101 ms 2380 KB Output is correct
4 Incorrect 88 ms 2976 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -