結果

問題 No.2376 障害物競プロ
ユーザー KowerKoint2010KowerKoint2010
提出日時 2023-07-03 12:41:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 512 ms / 4,000 ms
コード長 2,158 bytes
コンパイル時間 3,449 ms
コンパイル使用メモリ 207,548 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 09:45:18
合計ジャッジ時間 68,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 227 ms
4,376 KB
testcase_05 AC 319 ms
4,384 KB
testcase_06 AC 147 ms
4,380 KB
testcase_07 AC 512 ms
4,380 KB
testcase_08 AC 511 ms
4,384 KB
testcase_09 AC 502 ms
4,380 KB
testcase_10 AC 497 ms
4,384 KB
testcase_11 AC 435 ms
4,380 KB
testcase_12 AC 409 ms
4,380 KB
testcase_13 AC 482 ms
4,384 KB
testcase_14 AC 503 ms
4,380 KB
testcase_15 AC 455 ms
4,384 KB
testcase_16 AC 492 ms
4,380 KB
testcase_17 AC 415 ms
4,380 KB
testcase_18 AC 397 ms
4,380 KB
testcase_19 AC 425 ms
4,384 KB
testcase_20 AC 434 ms
4,384 KB
testcase_21 AC 432 ms
4,380 KB
testcase_22 AC 374 ms
4,380 KB
testcase_23 AC 291 ms
4,380 KB
testcase_24 AC 236 ms
4,380 KB
testcase_25 AC 113 ms
4,380 KB
testcase_26 AC 266 ms
4,380 KB
testcase_27 AC 225 ms
4,384 KB
testcase_28 AC 164 ms
4,380 KB
testcase_29 AC 115 ms
4,380 KB
testcase_30 AC 210 ms
4,380 KB
testcase_31 AC 154 ms
4,380 KB
testcase_32 AC 23 ms
4,380 KB
testcase_33 AC 81 ms
4,380 KB
testcase_34 AC 86 ms
4,380 KB
testcase_35 AC 47 ms
4,384 KB
testcase_36 AC 328 ms
4,380 KB
testcase_37 AC 323 ms
4,380 KB
testcase_38 AC 117 ms
4,384 KB
testcase_39 AC 410 ms
4,380 KB
testcase_40 AC 191 ms
4,384 KB
testcase_41 AC 106 ms
4,380 KB
testcase_42 AC 505 ms
4,384 KB
testcase_43 AC 505 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n, m; cin >> n >> m;
    vector<complex<ll>> xy(n*2, complex<ll>());
    for(int i = 0; i < n*2; i++) {
        ll x, y; cin >> x >> y;
        xy[i] = complex<ll>(x, y);
    }

    auto segment_intersect = [](complex<ll> p1, complex<ll> p2, complex<ll> q1, complex<ll> q2) {
        ll p1s = (conj(q2-q1)*(p1-q1)).imag();
        ll p2s = (conj(q2-q1)*(p2-q1)).imag();
        ll q1s = (conj(p2-p1)*(q1-p1)).imag();
        ll q2s = (conj(p2-p1)*(q2-p1)).imag();
        if(q1s == 0 && q2s == 0) {
            // 同一直線上
            if((conj(q1-p1)*(q2-p1)).real() <= 0) return true;
            if((conj(q1-p2)*(q2-p2)).real() <= 0) return true;
            if((conj(p1-q1)*(p2-q1)).real() <= 0) return true;
            return false;
        }
        if(((q1s>0)-(q1s<0)) * ((q2s>0)-(q2s<0)) > 0) return false;
        if(((p1s>0)-(p1s<0)) * ((p2s>0)-(p2s<0)) > 0) return false;
        return true;
    };

    vector<vector<double>> dist(n*2, vector<double>(n*2, 1e9));
    for(int i = 0; i < n*2; i++) {
        for(int j = 0; j < n*2; j++) {
            if(i == j) {
                dist[i][j] = 0;
                continue;
            }
            if((i>>1) == (j>>1)) continue;
            bool ok = true;
            for(int k = 0; k < n; k++) {
                if(k == (i>>1) || k == (j>>1)) continue;
                ok &= !segment_intersect(xy[i], xy[j], xy[k*2], xy[k*2+1]);
            }
            if(i == 0 && j == 3) {
                cerr << segment_intersect(xy[i], xy[j], xy[4], xy[5]) << endl;
            }
            if(ok) dist[i][j] = sqrt(norm(xy[i] - xy[j]));
        }
    }
    for(int k = 0; k < n*2; k++) {
        for(int i = 0; i < n*2; i++) {
            for(int j = 0; j < n*2; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    while(m--) {
        int a, b, c, d; cin >> a >> b >> c >> d; a--; b--; c--; d--;
        cout << dist[a*2+b][c*2+d] << '\n';
    }
}
0