結果
問題 | No.2376 障害物競プロ |
ユーザー |
![]() |
提出日時 | 2023-07-03 12:41:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 463 ms / 4,000 ms |
コード長 | 2,158 bytes |
コンパイル時間 | 2,141 ms |
コンパイル使用メモリ | 203,332 KB |
最終ジャッジ日時 | 2025-02-15 05:37:54 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#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';}}