답안 #201548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201548 2020-02-11T03:33:55 Z gs18115 Fences (JOI18_fences) C++14
100 / 100
64 ms 1400 KB
#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define semicolon ;
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
typedef pair<double,double>pd;
typedef pair<pd,pd>ln;
const int inf=1e9+7;
const ll INF=1e18;
const double eps=1e-9;
const ln xa(pd(0,0),pd(INF,0));
pd operator-(pd x,pd y)
{
    return pd(x.fi-y.fi,x.se-y.se);
}
inline double ccw(pd x,pd y)
{
    return x.fi*y.se-x.se*y.fi;
}
inline double sq(double x)
{
    return x*x;
}
inline double dist(pd x,pd y)
{
    return sqrt(sq(x.fi-y.fi)+sq(x.se-y.se));
}
inline double dot(pd x,pd y)
{
    return x.fi*y.fi+x.se*y.se;
}
inline bool cross(ln x,ln y)
{
    bool xc=ccw(x.fi-y.fi,x.se-y.fi)*ccw(x.fi-y.se,x.se-y.se)<0;
    swap(x,y);
    bool yc=ccw(x.fi-y.fi,x.se-y.fi)*ccw(x.fi-y.se,x.se-y.se)<0;
    return xc&&yc;
}
inline bool cross2(ln x,ln y)
{
    bool xc=ccw(x.fi-y.fi,x.se-y.fi)*ccw(x.fi-y.se,x.se-y.se)<1e-3;
    swap(x,y);
    bool yc=ccw(x.fi-y.fi,x.se-y.fi)*ccw(x.fi-y.se,x.se-y.se)<1e-3;
    return xc&&yc;
}
inline pd cut(ln x,double r)
{
    return pd(x.fi.fi*(1-r)+x.se.fi*r,x.fi.se*(1-r)+x.se.se*r);
}
inline pd perp(pd x,ln y)
{
    double rs=0;
    double re=1;
    while(re-rs>eps)
    {
        double r1=(rs*2+re)/3;
        double r2=(rs+re*2)/3;
        if(dist(x,cut(y,r1))<dist(x,cut(y,r2)))
            re=r2;
        else
            rs=r1;
    }
    return cut(y,rs);
}
double d[505][505];
inline void init(int n)
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            d[i][j]=INF;
    for(int i=0;i<n;i++)
        d[i][i]=0;
    return;
}
inline void app(int i,int j,double y)
{
    d[i][j]=min(d[i][j],y);
    d[j][i]=min(d[j][i],y);
    return;
}
vector<ln>rs;
inline void app(int i,int j,int sz,pd x,pd y)
{
    for(ln&t:rs)
        if(cross(t,ln(x,y)))
            return;
    double nd=dist(x,y);
    if(cross(xa,ln(x,y)))
        app(i,j+sz,nd),app(i+sz,j,nd);
    else
        app(i,j,nd),app(i+sz,j+sz,nd);
    return;
}
inline void floyd(int n)
{
    for(int k=0;k<n;k++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    return;
}
inline void cal(double&x)
{
    x+=x>0?eps:eps;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    double s;
    cin>>n>>s;
    vector<ln>v;
    vector<pd>rp;
    rp.eb(s,s),rp.eb(-s,s),rp.eb(-s,-s),rp.eb(s,-s);
    rs.eb(rp[0],rp[2]);
    rs.eb(rp[1],rp[3]);
    rs.eb(pd(s,0),pd(-s,0));
    rs.eb(pd(0,s),pd(0,-s));
    for(pd&t:rp)
        v.eb(t,t);
    for(int i=0;i<n;i++)
    {
        pd x,y;
        cin>>x.fi>>x.se>>y.fi>>y.se;
        if(x.se==0)
            x.se=eps;
        if(y.se==0)
            y.se=eps;
        if(cross2(xa,ln(x,y)))
        {
            if(x.se<y.se)
                swap(x,y);
            if(x.se>eps)
                v.eb(x,cut(ln(x,y),x.se/(x.se-y.se))),v.back().se.se+=eps;
            if(y.se<-eps)
                v.eb(cut(ln(x,y),x.se/(x.se-y.se)),y),v.back().fi.se-=eps;
        }
        else
            v.eb(x,y);
    }
    n=v.size();
    init(n*2);
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            app(i,j,n,v[i].fi,v[j].fi);
            app(i,j,n,v[i].fi,v[j].se);
            app(i,j,n,v[i].se,v[j].fi);
            app(i,j,n,v[i].se,v[j].se);
            app(i,j,n,v[i].fi,perp(v[i].fi,v[j]));
            app(i,j,n,v[i].se,perp(v[i].se,v[j]));
            app(i,j,n,v[j].fi,perp(v[j].fi,v[i]));
            app(i,j,n,v[j].se,perp(v[j].se,v[i]));
        }
    }
    floyd(n*2);
    double m=INF;
    for(int i=0;i<n;i++)
        m=min(m,d[i][i+n]);
    cout<<fixed<<setprecision(12)<<m<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 408 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 408 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 508 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 408 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 380 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 508 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
37 Correct 5 ms 376 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 5 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 5 ms 376 KB Output is correct
44 Correct 53 ms 1272 KB Output is correct
45 Correct 52 ms 1144 KB Output is correct
46 Correct 54 ms 1272 KB Output is correct
47 Correct 49 ms 1144 KB Output is correct
48 Correct 47 ms 1144 KB Output is correct
49 Correct 54 ms 1272 KB Output is correct
50 Correct 49 ms 1144 KB Output is correct
51 Correct 53 ms 1272 KB Output is correct
52 Correct 51 ms 1272 KB Output is correct
53 Correct 51 ms 1272 KB Output is correct
54 Correct 53 ms 1272 KB Output is correct
55 Correct 61 ms 1400 KB Output is correct
56 Correct 57 ms 1272 KB Output is correct
57 Correct 47 ms 1144 KB Output is correct
58 Correct 50 ms 1272 KB Output is correct
59 Correct 51 ms 1272 KB Output is correct
60 Correct 56 ms 1272 KB Output is correct
61 Correct 62 ms 1272 KB Output is correct
62 Correct 6 ms 504 KB Output is correct
63 Correct 5 ms 504 KB Output is correct
64 Correct 42 ms 1144 KB Output is correct
65 Correct 42 ms 1144 KB Output is correct
66 Correct 42 ms 1140 KB Output is correct
67 Correct 62 ms 1272 KB Output is correct
68 Correct 64 ms 1400 KB Output is correct
69 Correct 44 ms 1144 KB Output is correct
70 Correct 40 ms 1144 KB Output is correct
71 Correct 43 ms 1400 KB Output is correct
72 Correct 44 ms 1144 KB Output is correct