Submission #58787

# Submission time Handle Problem Language Result Execution time Memory
58787 2018-07-19T11:52:21 Z andy627 None (KOI16_dist) C++17
0 / 100
121 ms 3216 KB
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#define LL long long
#define INF 9e18
using namespace std;

struct xyv{
    LL x,y,dx,dy,t;
}star[33333];

struct xyt{
    LL x,y;
    double t;

    bool operator<(const xyt A)const{
        if(t!=A.t) return t<A.t;
        if(y!=A.y) return y<A.y;
        return x<A.x;
    }
}ver[33333];

LL n,t;
vector<int> con;

LL ccw(int i,int j,int k){
    return (star[i].x*star[j].y+star[j].x*star[k].y+star[k].x*star[i].y)
    -(star[j].x*star[i].y+star[k].x*star[j].y+star[i].x*star[k].y);
}

void convex_hull(int day){
    int mnp=1;

    for(int i=1;i<=n;i++){
        ver[i].x=star[i].x+day*star[i].dx;
        ver[i].y=star[i].y+day*star[i].dy;

        if(ver[mnp].y>ver[i].y) mnp=i;
        if(ver[mnp].y==ver[i].y && ver[mnp].x>ver[i].x) mnp=i;
    }
    for(int i=1;i<=n;i++) ver[i].t=atan2(ver[i].y-ver[mnp].y,ver[i].x-ver[mnp].x);

    sort(ver+1,ver+n+1);

    con.clear();
    con.push_back(1);
    con.push_back(2);
    for(int i=3;i<=n;i++){
        int idx1=con.size()-2;
        int idx2=con.size()-1;

        while(idx1>=0 && ccw(con[idx1],con[idx2],i)<=0){
            con.pop_back();
            idx1=con.size()-2;
            idx2=con.size()-1;
        }
        con.push_back(i);
    }
}

LL dist(int i,int j){
    return (ver[con[i]].x-ver[con[j]].x)*(ver[con[i]].x-ver[con[j]].x)
    +(ver[con[i]].y-ver[con[j]].y)*(ver[con[i]].y-ver[con[j]].y);
}

LL rotating_calipers(){
    int siz=con.size();

    LL ans=0;
    for(int i=0,j=0;i<siz;i++){
        while(dist(i,j)<=dist(i,(j+1)%siz)) j=(j+1)%siz;
        ans=max(ans,dist(i,j));
    }

    return ans;
}

LL solve(int day){
    convex_hull(day);
    return rotating_calipers();
}

int main(){
    scanf("%lld %lld",&n,&t);
    for(int i=1;i<=n;i++) scanf("%lld %lld %lld %lld",&star[i].x,&star[i].y,&star[i].dx,&star[i].dy);

    int s=1,e=t,m1,m2;
    while(e-s>2){
        m1=(s+s+e)/3; m2=(s+e+e)/3;

        LL res1=solve(m1);
        LL res2=solve(m2);

        if(res1<=res2) e=m2;
        if(res1>=res2) s=m1;
    }

    int ans_day=0;
    LL ans_dist=INF,res;
    for(int i=s;i<=e;i++){
        res=solve(i);
        if(ans_dist>res){
            ans_day=i;
            ans_dist=res;
        }
    }

    printf("%d\n%lld\n",ans_day,ans_dist);

    return 0;
}

Compilation message

dist.cpp: In function 'int main()':
dist.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld",&n,&t);
     ~~~~~^~~~~~~~~~~~~~~~~~~
dist.cpp:86:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%lld %lld %lld %lld",&star[i].x,&star[i].y,&star[i].dx,&star[i].dy);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 121 ms 3216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -