結果
問題 | No.2376 障害物競プロ |
ユーザー |
|
提出日時 | 2023-07-07 21:46:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 528 ms / 4,000 ms |
コード長 | 4,971 bytes |
コンパイル時間 | 942 ms |
コンパイル使用メモリ | 83,232 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-21 17:37:28 |
合計ジャッジ時間 | 55,059 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include<iostream>#include<cassert>#include<cmath>#include<iomanip>using namespace std;#include<iostream>#include<algorithm>#include<vector>using Int=long long;int sign(Int a){return a>0?1:a<0?-1:0;}Int sqr(Int a){return a*a;}struct Rational{Int a,b;Rational(Int a_=0):a(a_),b(1){}Rational(Int a_,Int b_){Int g=a_,h=b_;while(h){Int t=g%h;g=h;h=t;}a=a_/g;b=b_/g;if(b<0)a=-a,b=-b;}bool operator<(const Rational&r)const{return a*r.b<r.a*b;}bool operator==(const Rational&r)const{return a==r.a&&b==r.b;}};struct Point{Int x,y;Point(Int x_=0,Int y_=0):x(x_),y(y_){}Point operator-()const{return Point(-x,-y);}Point operator+(const Point&p)const{return Point(x+p.x,y+p.y);}Point operator-(const Point&p)const{return Point(x-p.x,y-p.y);}Point operator*(const Int k)const{return Point(x*k,y*k);}bool operator<(const Point&p)const{return x==p.x?y<p.y:x<p.x;}bool operator==(const Point&p)const{return x==p.x&&y==p.y;}};istream&operator>>(istream&is,Point&p){return is>>p.x>>p.y;}ostream&operator<<(ostream&os,const Point&p){return os<<p.x<<' '<<p.y;}struct Line{Point p1,p2;Line(Point p1_=Point(),Point p2_=Point()):p1(p1_),p2(p2_){}};struct Segment:Line{Segment(Point p1_=Point(),Point p2_=Point()):Line(p1_,p2_){}};struct Circle{Point o;Int r;Circle(Point o_=Point(),Int r_=0):o(o_),r(r_){}};using Polygon=vector<Point>;//function list beginPoint vec(const Line&);Int norm(const Point&);Int norm(const Line&);int argtype(const Point&);//(-pi,0]->-1,(0,pi]->1,(0,0)->0bool argless(const Point&,const Point&);//sorting points with argInt dot(const Point&,const Point&);Int cross(const Point&,const Point&);enum{ONLINE_FRONT=-2,CLOCKWISE=-1,ON_SEGMENT=0,COUNTER_CLOCKWISE=1,ONLINE_BACK=2};int ccw(const Point&,const Point&);int ccw(const Point&,const Point&,const Point&);int ccw(const Line&,const Point&);bool orthogonal(const Point&,const Point&);bool orthogonal(const Line&,const Line&);bool parallel(const Point&,const Point&);bool parallel(const Line&,const Line&);bool intersect(const Line&,const Point&);bool intersect(const Line&,const Line&);bool intersect(const Segment&,const Point&);bool intersect(const Segment&,const Segment&);bool intersect(const Line&,const Segment&);bool intersect(const Segment&,const Line&);bool intersect(const Circle&,const Point&);int intersect(const Circle&,const Line&);//overflow, count contactsint intersect(const Circle&,const Segment&);//overflow, count contactsbool intersect(const Circle&,const Circle&);int count_tangent(const Circle&,const Circle&);//count common tangentsInt distance2(const Point&,const Point&);Rational distance2(const Line&,const Point&);Rational distance2(const Line&,const Line&);Rational distance2(const Segment&,const Point&);Rational distance2(const Segment&,const Segment&);Rational distance2(const Line&,const Segment&);Rational distance2(const Segment&,const Line&);bool is_convex(const Polygon&);Polygon convex_hull(Polygon,bool=false);enum{OUT,ON,IN};int contain(const Polygon&,const Point&);int contain(const Circle&,const Point&);int contain(const Circle&,const Segment&);int convex_contain(const Polygon&,const Point&);//O(log |P|)Int diameter2(Polygon P);//function list endPoint vec(const Line&s){return s.p2-s.p1;}Int norm(const Point&p){return p.x*p.x+p.y*p.y;}Int norm(const Line&s){return norm(vec(s));}int argtype(const Point&a){return a.y<0?-1:a.y>0?1:a.x<0?1:a.x>0?-1:0;}bool argless(const Point&a,const Point&b){int at=argtype(a),bt=argtype(b);return at!=bt?at<bt:ccw(a,b)>0;}Int dot(const Point&a,const Point&b){return a.x*b.x+a.y*b.y;}Int cross(const Point&a,const Point&b){return a.x*b.y-a.y*b.x;}int ccw(const Point&a,const Point&b){Int crs=cross(a,b);return crs>0?COUNTER_CLOCKWISE:crs<0?CLOCKWISE:dot(a,b)<0?ONLINE_BACK:norm(a)<norm(b)?ONLINE_FRONT:ON_SEGMENT;}int ccw(const Point&a,const Point&b,const Point&c){return ccw(b-a,c-a);}int ccw(const Line&s,const Point&p){return ccw(s.p1,s.p2,p);}bool intersect(const Segment&s,const Segment&t){return ccw(s,t.p1)*ccw(s,t.p2)<=0&&ccw(t,s.p1)*ccw(t,s.p2)<=0;}int N,M;Point P[300];Segment L[150];long double D[300][300];int main(){ios::sync_with_stdio(false);cin.tie(nullptr);cin>>N>>M;for(int i=0;i<2*N;i++)cin>>P[i];for(int i=0;i<N;i++)L[i]=Segment(P[i*2],P[i*2+1]);for(int i=0;i<2*N;i++)for(int j=0;j<2*N;j++){if(i==j){D[i][j]=0;continue;}D[i][j]=1e150;Segment s(P[i],P[j]);bool ok=true;for(int k=0;k<N;k++){if(i/2==k||j/2==k)continue;if(intersect(s,L[k])){ok=false;break;}}if(ok)D[i][j]=hypot(P[i].x-P[j].x,P[i].y-P[j].y);}for(int k=0;k<2*N;k++)for(int i=0;i<2*N;i++)for(int j=0;j<2*N;j++){D[i][j]=min(D[i][j],D[i][k]+D[k][j]);}for(;M--;){int a,b,c,d;cin>>a>>b>>c>>d;a=(a-1)*2+b-1;c=(c-1)*2+d-1;cout<<fixed<<setprecision(16)<<D[a][c]<<"\n";}}