結果

問題 No.2376 障害物競プロ
ユーザー SSRSSSRS
提出日時 2023-07-07 22:18:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 826 ms / 4,000 ms
コード長 1,632 bytes
コンパイル時間 5,015 ms
コンパイル使用メモリ 171,128 KB
実行使用メモリ 4,456 KB
最終ジャッジ日時 2023-09-28 23:42:34
合計ジャッジ時間 77,448 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 495 ms
4,376 KB
testcase_05 AC 698 ms
4,380 KB
testcase_06 AC 275 ms
4,380 KB
testcase_07 AC 826 ms
4,380 KB
testcase_08 AC 821 ms
4,384 KB
testcase_09 AC 812 ms
4,384 KB
testcase_10 AC 808 ms
4,384 KB
testcase_11 AC 727 ms
4,384 KB
testcase_12 AC 698 ms
4,384 KB
testcase_13 AC 803 ms
4,380 KB
testcase_14 AC 810 ms
4,388 KB
testcase_15 AC 759 ms
4,384 KB
testcase_16 AC 793 ms
4,384 KB
testcase_17 AC 701 ms
4,380 KB
testcase_18 AC 681 ms
4,384 KB
testcase_19 AC 725 ms
4,380 KB
testcase_20 AC 751 ms
4,384 KB
testcase_21 AC 745 ms
4,384 KB
testcase_22 AC 669 ms
4,384 KB
testcase_23 AC 437 ms
4,380 KB
testcase_24 AC 519 ms
4,380 KB
testcase_25 AC 245 ms
4,380 KB
testcase_26 AC 587 ms
4,388 KB
testcase_27 AC 498 ms
4,384 KB
testcase_28 AC 265 ms
4,380 KB
testcase_29 AC 246 ms
4,380 KB
testcase_30 AC 228 ms
4,384 KB
testcase_31 AC 289 ms
4,384 KB
testcase_32 AC 35 ms
4,380 KB
testcase_33 AC 100 ms
4,384 KB
testcase_34 AC 141 ms
4,384 KB
testcase_35 AC 100 ms
4,384 KB
testcase_36 AC 461 ms
4,380 KB
testcase_37 AC 638 ms
4,380 KB
testcase_38 AC 228 ms
4,380 KB
testcase_39 AC 604 ms
4,396 KB
testcase_40 AC 161 ms
4,380 KB
testcase_41 AC 219 ms
4,380 KB
testcase_42 AC 817 ms
4,456 KB
testcase_43 AC 818 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const double INF = 1000000000;
struct point{
  int x, y;
  point(){
  }
  point(int x, int y): x(x), y(y){
  }
  point operator -(point P){
    return point(x - P.x, y - P.y);
  }
};
double abs(point P){
  return hypot(P.x, P.y);
}
double dist(point P, point Q){
  return abs(Q - P);
}
int cross(point A, point B){
  return A.x * B.y - A.y * B.x;
}
int main(){
  cout << fixed << setprecision(20);
  int N, M;
  cin >> N >> M;
  vector<point> P(N * 2);
  for (int i = 0; i < N * 2; i++){
    cin >> P[i].x >> P[i].y;
  }
  vector<vector<double>> D(N * 2, vector<double>(N * 2, INF));
  for (int i = 0; i < N * 2; i++){
    for (int j = i + 1; j < N * 2; j++){
      bool ok = true;
      for (int k = 0; k < N; k++){
        long long a = cross(P[k * 2] - P[i], P[j] - P[i]);
        long long b = cross(P[k * 2 + 1] - P[i], P[j] - P[i]);
        if (a > 0 && b < 0 || a < 0 && b > 0){
          long long c = cross(P[i] - P[k * 2], P[k * 2 + 1] - P[k * 2]);
          long long d = cross(P[j] - P[k * 2], P[k * 2 + 1] - P[k * 2]);
          if (c > 0 && d < 0 || c < 0 && d > 0){
            ok = false;
          }
        }
      }
      if (ok){
        D[i][j] = dist(P[i], P[j]);
        D[j][i] = dist(P[i], P[j]);
      }
    }
  }
  for (int i = 0; i < N * 2; i++){
    for (int j = 0; j < N * 2; j++){
      for (int k = 0; k < N * 2; k++){
        D[j][k] = min(D[j][k], D[j][i] + D[i][k]);
      }
    }
  }
  for (int i = 0; i < M; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    cout << D[a * 2 + b][c * 2 + d] << endl;
  }
}
0