結果

問題 No.2376 障害物競プロ
ユーザー momoyuumomoyuu
提出日時 2023-07-08 15:34:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,465 bytes
コンパイル時間 3,137 ms
コンパイル使用メモリ 151,472 KB
実行使用メモリ 5,844 KB
最終ジャッジ日時 2023-09-29 16:55:05
合計ジャッジ時間 67,828 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 453 ms
4,376 KB
testcase_05 AC 665 ms
4,384 KB
testcase_06 AC 247 ms
4,388 KB
testcase_07 AC 674 ms
4,388 KB
testcase_08 AC 710 ms
4,384 KB
testcase_09 AC 728 ms
4,380 KB
testcase_10 AC 647 ms
4,504 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 692 ms
4,388 KB
testcase_14 AC 643 ms
4,388 KB
testcase_15 AC 677 ms
4,420 KB
testcase_16 AC 685 ms
4,388 KB
testcase_17 AC 609 ms
4,408 KB
testcase_18 AC 559 ms
4,384 KB
testcase_19 AC 723 ms
5,844 KB
testcase_20 AC 713 ms
5,560 KB
testcase_21 AC 721 ms
5,672 KB
testcase_22 AC 576 ms
4,388 KB
testcase_23 AC 346 ms
4,388 KB
testcase_24 AC 463 ms
4,388 KB
testcase_25 AC 227 ms
4,384 KB
testcase_26 AC 508 ms
4,388 KB
testcase_27 AC 447 ms
4,384 KB
testcase_28 AC 228 ms
4,388 KB
testcase_29 AC 226 ms
4,388 KB
testcase_30 AC 156 ms
4,384 KB
testcase_31 AC 242 ms
4,388 KB
testcase_32 AC 28 ms
4,384 KB
testcase_33 AC 76 ms
4,388 KB
testcase_34 AC 121 ms
4,388 KB
testcase_35 AC 88 ms
4,388 KB
testcase_36 AC 367 ms
4,392 KB
testcase_37 AC 555 ms
4,388 KB
testcase_38 AC 209 ms
4,384 KB
testcase_39 AC 524 ms
4,388 KB
testcase_40 AC 92 ms
4,388 KB
testcase_41 AC 199 ms
4,388 KB
testcase_42 AC 775 ms
5,540 KB
testcase_43 AC 749 ms
5,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<cassert>
#include<cmath>
#include<iomanip>
using namespace std;
using ll = long long;

using dat = pair<ll,ll>;

template< typename T >
struct edge{
    int from,to;
    T cost;
    edge(int from,int to, T cost):from(from),to(to),cost(cost){};
    edge &operator=(const int& x){
        to = x;
        return *this;
    }
};

template< typename T >
struct graph{
    int n;
    vector<vector<edge<T>>> e;
    graph(int n):n(n),e(n){}

    void add_edge(int from,int to,T cost){
        e[from].emplace_back(from,to,cost);
    }

    vector<edge<T>> &operator[](int i) {
        return e[i];
    }
};

template< typename T >
vector<vector<T>> warshallfloyd(graph<T>& g,T const inf = (T)1e9){
    int n = g.n;
    vector<vector<T>> dist(n,vector<T>(n,inf));
    for(int i = 0;i<n;i++){
        dist[i][i] = 0;
    }
    for(int i = 0;i<n;i++){
        for(edge<T> e:g[i]){
            dist[i][e.to] = e.cost;
        }
    }
    for(int k = 0;k<n;k++){
        for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++){
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    return dist;
}


int ccw(dat a,dat b,dat c){
    ll da = b.first - a.first;
    ll db = b.second - a.second;
    ll dc = c.first - a.first;
    ll dd = c.second - a.second;
    if(da*dd-db*dc>0) return 1;
    if(da*dd-db*dc<0) return -1;
    if(da*db+dc*dd<0) return 2;
    if(da*da+db*db<dc*dc+dd*dd) return -2;
    return 0;
}

bool isok(dat a,dat b,dat c,dat d){
    if(ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0) return 0;
    else return 1;


}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<ll>> x(2,vector<ll>(n)),y(2,vector<ll>(n));
    for(int i = 0;i<n;i++) for(int j = 0;j<2;j++) cin>>x[j][i]>>y[j][i];
    vector<pair<ll,ll>> d;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<2;j++){
            d.push_back(make_pair(x[j][i],y[j][i]));
        }
    }
    set<pair<dat,dat>> s;
    sort(d.begin(),d.end());
    for(int i = 0;i<n;i++){
        dat now = {x[0][i],y[0][i]};
        dat nxt = {x[1][i],y[1][i]};
        s.insert(make_pair(now,nxt));
        s.insert(make_pair(now,nxt));
    }
    int al = d.size();
    graph<double> g(al);
    for(int i = 0;i<al;i++){
        for(int j = i + 1;j<al;j++){
            dat a = d[i];
            dat b = d[j];
            if(s.count(make_pair(a,b))) continue;
            if(s.count(make_pair(b,a))) continue;
            bool ok = true;
            for(int k = 0;k<n;k++){
                dat c = {x[0][k],y[0][k]};
                dat dd = {x[1][k],y[1][k]};
                if(c==a||c==b||dd==a||dd==b) continue;
                if(isok(a,b,c,dd)) continue;
                ok = false;
                
           // cout<<a.first<<" "<<a.second<<" "<<b.first<<" "<<b.second<<" "<<k<<endl;
                break;
            }
            if(!ok) continue;
            int ni = lower_bound(d.begin(),d.end(),a) - d.begin();
            int nj = lower_bound(d.begin(),d.end(),b) - d.begin();
            ll dx = a.first - b.first;
            ll dy = a.second - b.second;
            double now = sqrt(dx*dx+dy*dy);
            g.add_edge(ni,nj,now);
            g.add_edge(nj,ni,now);
        }
    }
    for(int i = 0;i<n;i++){
        dat a = {x[0][i],y[0][i]};
        dat b = {x[1][i],y[1][i]};
        bool ok = true;
        for(int j = 0;j<n;j++){
            if(i==j) continue;
            dat c = {x[0][j],y[0][j]};
            dat dd = {x[1][j],y[1][j]};
            if(c==a||c==b||dd==a||dd==c) continue;
            if(isok(a,b,c,dd)) continue;
            ok = false;
            break;
        }
        if(!ok) continue;
        int ni = lower_bound(d.begin(),d.end(),a) - d.begin();
        int nj = lower_bound(d.begin(),d.end(),b) - d.begin();
        ll dx = a.first - b.first;
        ll dy = a.second - b.second;
        double now = sqrt(dx*dx+dy*dy);
        g.add_edge(ni,nj,now);
        g.add_edge(nj,ni,now);
    }
    auto di = warshallfloyd<double>(g);
    cout<<fixed<<setprecision(15);
    while(m--){
        int i,j,k,l;
        cin>>i>>j>>k>>l;
        i--;j--;k--;l--;
        dat a = {x[j][i],y[j][i]};
        dat b = {x[l][k],y[l][k]};
        int ni = lower_bound(d.begin(),d.end(),a) - d.begin();
        int nj = lower_bound(d.begin(),d.end(),b) - d.begin();
        cout<<di[ni][nj]<<endl;
    }


}

0