結果
問題 | No.2376 障害物競プロ |
ユーザー |
![]() |
提出日時 | 2023-07-08 10:02:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 511 ms / 4,000 ms |
コード長 | 1,795 bytes |
コンパイル時間 | 1,666 ms |
コンパイル使用メモリ | 196,308 KB |
最終ジャッジ日時 | 2025-02-15 08:53:35 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef signed long long ll;#define _P(...) (void)printf(__VA_ARGS__)#define FOR(x,to) for(x=0;x<(to);x++)#define FORR(x,arr) for(auto& x:arr)#define FORR2(x,y,arr) for(auto& [x,y]:arr)#define ALL(a) (a.begin()),(a.end())#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}//-------------------------------------------------------int N,M;ll X[333],Y[333];double E[333][333];int cross(int a,int b,int c,int d) {ll XX[3],YY[3];XX[0]=X[b]-X[a]; YY[0]=Y[b]-Y[a];XX[1]=X[c]-X[a]; YY[1]=Y[c]-Y[a];XX[2]=X[d]-X[a]; YY[2]=Y[d]-Y[a];ll c1=XX[0]*YY[1]-XX[1]*YY[0];ll c2=XX[0]*YY[2]-XX[2]*YY[0];if(c1>=0&&c2>=0||c1<=0&&c2<=0) return 0;XX[0]=X[d]-X[c]; YY[0]=Y[d]-Y[c];XX[1]=X[a]-X[c]; YY[1]=Y[a]-Y[c];XX[2]=X[b]-X[c]; YY[2]=Y[b]-Y[c];c1=XX[0]*YY[1]-XX[1]*YY[0];c2=XX[0]*YY[2]-XX[2]*YY[0];if(c1>=0&&c2>=0||c1<=0&&c2<=0) return 0;return 1;}void solve() {int i,j,k,l,r,x,y; string s;cin>>N>>M;N*=2;FOR(i,N) cin>>X[i]>>Y[i];FOR(x,N) FOR(y,N) {E[x][y]=hypot(X[x]-X[y],Y[x]-Y[y]);if(x==y) continue;FOR(i,N/2) {if(x/2==i) continue;if(y/2==i) continue;if(cross(x,y,i*2,i*2+1)) E[x][y]=1LL<<60;}}FOR(k,N) FOR(x,N) FOR(y,N) E[x][y]=min(E[x][y],E[x][k]+E[k][y]);while(M--) {int a,b,c,d;cin>>a>>b>>c>>d;_P("%.12lf\n",E[(a-1)*2+(b-1)][(c-1)*2+(d-1)]);}}int main(int argc,char** argv){string s;int i;if(argc==1) ios::sync_with_stdio(false), cin.tie(0);FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);cout.tie(0); solve(); return 0;}