結果

問題 No.2376 障害物競プロ
ユーザー MichirakaraMichirakara
提出日時 2023-07-01 11:47:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 783 ms / 4,000 ms
コード長 1,977 bytes
コンパイル時間 4,368 ms
コンパイル使用メモリ 206,356 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-09-23 07:44:07
合計ジャッジ時間 66,248 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 466 ms
4,376 KB
testcase_05 AC 649 ms
4,380 KB
testcase_06 AC 260 ms
4,384 KB
testcase_07 AC 733 ms
4,380 KB
testcase_08 AC 723 ms
4,408 KB
testcase_09 AC 725 ms
4,384 KB
testcase_10 AC 722 ms
4,384 KB
testcase_11 AC 655 ms
4,384 KB
testcase_12 AC 620 ms
4,380 KB
testcase_13 AC 720 ms
4,380 KB
testcase_14 AC 709 ms
4,384 KB
testcase_15 AC 699 ms
4,384 KB
testcase_16 AC 717 ms
4,384 KB
testcase_17 AC 627 ms
4,392 KB
testcase_18 AC 609 ms
4,388 KB
testcase_19 AC 751 ms
4,392 KB
testcase_20 AC 762 ms
4,420 KB
testcase_21 AC 760 ms
4,384 KB
testcase_22 AC 604 ms
4,380 KB
testcase_23 AC 376 ms
4,380 KB
testcase_24 AC 493 ms
4,380 KB
testcase_25 AC 232 ms
4,380 KB
testcase_26 AC 551 ms
4,384 KB
testcase_27 AC 470 ms
4,384 KB
testcase_28 AC 237 ms
4,380 KB
testcase_29 AC 237 ms
4,384 KB
testcase_30 AC 175 ms
4,380 KB
testcase_31 AC 266 ms
4,384 KB
testcase_32 AC 31 ms
4,380 KB
testcase_33 AC 82 ms
4,380 KB
testcase_34 AC 126 ms
4,380 KB
testcase_35 AC 96 ms
4,380 KB
testcase_36 AC 391 ms
4,380 KB
testcase_37 AC 583 ms
4,380 KB
testcase_38 AC 209 ms
4,380 KB
testcase_39 AC 517 ms
4,380 KB
testcase_40 AC 105 ms
4,384 KB
testcase_41 AC 206 ms
4,384 KB
testcase_42 AC 783 ms
4,388 KB
testcase_43 AC 783 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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((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]<<'\n';
    }
}
0