結果
問題 | No.2376 障害物競プロ |
ユーザー | Michirakara |
提出日時 | 2023-07-01 11:39:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 774 ms / 4,000 ms |
コード長 | 1,985 bytes |
コンパイル時間 | 2,717 ms |
コンパイル使用メモリ | 207,708 KB |
実行使用メモリ | 4,508 KB |
最終ジャッジ日時 | 2023-09-23 07:42:09 |
合計ジャッジ時間 | 65,999 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 467 ms
4,380 KB |
testcase_05 | AC | 653 ms
4,376 KB |
testcase_06 | AC | 251 ms
4,384 KB |
testcase_07 | AC | 725 ms
4,380 KB |
testcase_08 | AC | 728 ms
4,392 KB |
testcase_09 | AC | 719 ms
4,448 KB |
testcase_10 | AC | 731 ms
4,388 KB |
testcase_11 | AC | 649 ms
4,392 KB |
testcase_12 | AC | 615 ms
4,380 KB |
testcase_13 | AC | 734 ms
4,384 KB |
testcase_14 | AC | 714 ms
4,380 KB |
testcase_15 | AC | 693 ms
4,508 KB |
testcase_16 | AC | 718 ms
4,380 KB |
testcase_17 | AC | 631 ms
4,384 KB |
testcase_18 | AC | 606 ms
4,472 KB |
testcase_19 | AC | 745 ms
4,388 KB |
testcase_20 | AC | 757 ms
4,380 KB |
testcase_21 | AC | 767 ms
4,384 KB |
testcase_22 | AC | 591 ms
4,384 KB |
testcase_23 | AC | 366 ms
4,380 KB |
testcase_24 | AC | 488 ms
4,388 KB |
testcase_25 | AC | 226 ms
4,384 KB |
testcase_26 | AC | 546 ms
4,384 KB |
testcase_27 | AC | 458 ms
4,384 KB |
testcase_28 | AC | 236 ms
4,392 KB |
testcase_29 | AC | 232 ms
4,384 KB |
testcase_30 | AC | 172 ms
4,384 KB |
testcase_31 | AC | 258 ms
4,384 KB |
testcase_32 | AC | 30 ms
4,384 KB |
testcase_33 | AC | 82 ms
4,380 KB |
testcase_34 | AC | 126 ms
4,384 KB |
testcase_35 | AC | 91 ms
4,384 KB |
testcase_36 | AC | 382 ms
4,380 KB |
testcase_37 | AC | 577 ms
4,380 KB |
testcase_38 | AC | 207 ms
4,384 KB |
testcase_39 | AC | 518 ms
4,384 KB |
testcase_40 | AC | 104 ms
4,380 KB |
testcase_41 | AC | 205 ms
4,384 KB |
testcase_42 | AC | 770 ms
4,380 KB |
testcase_43 | AC | 774 ms
4,384 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //座標を表す構造体 struct coord{ long long x,y; bool operator==(coord&other){ return this->x==other.x && this->y==other.y; } }; int main(){ int N,M; cin>>N>>M; vector<vector<coord>> xy(N); for(int i=0;i<N;i++){ long long x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; xy[i]={{x1,y1},{x2,y2}}; } //Floyd-Warshall法を実行する vector<vector<double>> dp(N+N,vector<double>(N+N,1E18)); //DPテーブルの初期化 for(int i=0;i<N+N;i++){ for(int j=0;j<N+N;j++){ if(i==j){ dp[i][j]=0; continue; } coord xy1=xy[i%N][i/N],xy2=xy[j%N][j/N]; bool flag=true; for(int k=0;k<N;k++){ coord xy3=xy[k][0],xy4=xy[k][1]; if(xy3==xy1 || xy3==xy2 || xy4==xy1 || xy4==xy2){ continue; } //線分の交差判定 long long s=(xy1.x-xy2.x)*(xy3.y-xy1.y)-(xy1.y-xy2.y)*(xy3.x-xy1.x), t=(xy1.x-xy2.x)*(xy4.y-xy1.y)-(xy1.y-xy2.y)*(xy4.x-xy1.x), s2=(xy3.x-xy4.x)*(xy1.y-xy3.y)-(xy3.y-xy4.y)*(xy1.x-xy3.x), t2=(xy3.x-xy4.x)*(xy2.y-xy3.y)-(xy3.y-xy4.y)*(xy2.x-xy3.x); if(!(s*t>=0 || s2*t2>=0)){ flag=false; break; } } if(flag){ dp[i][j]=sqrt(double((xy1.x-xy2.x)*(xy1.x-xy2.x)+(xy1.y-xy2.y)*(xy1.y-xy2.y))); } } } //DPテーブルの更新 for(int k=0;k<N+N;k++){ for(int i=0;i<N+N;i++){ for(int j=0;j<N+N;j++){ dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]); } } } //クエリに答える cout<<setprecision(20); while(M--){ int a,b,c,d;cin>>a>>b>>c>>d; cout<<dp[a-1+(b-1)*N][c-1+(d-1)*N]<<endl; } }