結果

問題 No.2376 障害物競プロ
ユーザー karinohitokarinohito
提出日時 2023-07-07 23:03:04
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 866 ms / 4,000 ms
コード長 2,241 bytes
コンパイル時間 4,684 ms
コンパイル使用メモリ 267,004 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-21 19:22:58
合計ジャッジ時間 69,562 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using mint = modint998244353;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;

using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define rep(i,n) for(ll i=(ll)(0); i<(ll(n)); ++i)
#define all(x) (x).begin(), (x).end()

vector<double> X, Y;
double dis(ll i, ll j) {
    double dx = X[i] - X[j];
    double dy = Y[i] - Y[j];
    return sqrt(dx * dx + dy * dy);
}

const double EPS = 1e-12;
bool cross(ll a, ll b, ll c, ll d) {
    double s, t;
    s = (X[a] - X[b]) * (Y[c] - Y[a]) - (Y[a] - Y[b]) * (X[c] - X[a]);
    t = (X[a] - X[b]) * (Y[d] - Y[a]) - (Y[a] - Y[b]) * (X[d] - X[a]);
    if (s * t > -EPS)
        return false;

    s = (X[c] - X[d]) * (Y[a] - Y[c]) - (Y[c] - Y[d]) * (X[a] - X[c]);
    t = (X[c] - X[d]) * (Y[b] - Y[c]) - (Y[c] - Y[d]) * (X[b] - X[c]);
    if (s * t > -EPS)
        return false;
    return true;
}

void warshall_floyd(int n, vvd& d) {
    for (int k = 0; k < n; k++) {       // 経由する頂点
        for (int i = 0; i < n; i++) {    // 始点
            for (int j = 0; j < n; j++) {  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}
int main() {

    ll N, M;
    cin >> N >> M;
    vvd D(2 * N, vd(2 * N, 1e18));
    rep(i, 2 * N)D[i][i] = 0;
    X.resize(2 * N);
    Y.resize(2 * N);
    rep(i, 2 * N)cin >> X[i] >> Y[i];
    rep(i, N) {
        bool OK = 1;
        //re
        //D[2 * i][2 * i + 1] = D[2 * i + 1][2 * i] = dis(2 * i, 2 * i + 1);
    }
    rep(j, 2 * N) {
        rep(k, 2 * N) {
            bool OK = 1;
            rep(i, N) {
                if (j == k || j / 2 == i || k / 2 == i)continue;
                if (cross(2 * i, 2 * i + 1, j, k))OK = 0;
            }
            if (OK)
                D[j][k] = D[k][j] = dis(k, j);
        }

    }
    warshall_floyd(2 * N, D);
    cout << fixed << setprecision(16);
    rep(i, M) {
        ll A, B, C, DD;
        cin >> A >> B >> C >> DD;
        A--; C--;
        A = 2 * A + B - 1;
        C = 2 * C + DD - 1;
        cout << D[A][C] << endl;
    }
}
0