結果

問題 No.2376 障害物競プロ
ユーザー KudeKude
提出日時 2023-07-07 22:22:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 360 ms / 4,000 ms
コード長 4,847 bytes
コンパイル時間 3,155 ms
コンパイル使用メモリ 225,468 KB
実行使用メモリ 4,444 KB
最終ジャッジ日時 2023-09-28 23:48:27
合計ジャッジ時間 53,359 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 1 ms
4,380 KB
testcase_04 AC 210 ms
4,380 KB
testcase_05 AC 292 ms
4,380 KB
testcase_06 AC 116 ms
4,380 KB
testcase_07 AC 326 ms
4,376 KB
testcase_08 AC 330 ms
4,380 KB
testcase_09 AC 314 ms
4,384 KB
testcase_10 AC 312 ms
4,380 KB
testcase_11 AC 257 ms
4,380 KB
testcase_12 AC 236 ms
4,384 KB
testcase_13 AC 319 ms
4,384 KB
testcase_14 AC 323 ms
4,384 KB
testcase_15 AC 295 ms
4,380 KB
testcase_16 AC 308 ms
4,380 KB
testcase_17 AC 243 ms
4,380 KB
testcase_18 AC 229 ms
4,384 KB
testcase_19 AC 343 ms
4,384 KB
testcase_20 AC 355 ms
4,384 KB
testcase_21 AC 357 ms
4,384 KB
testcase_22 AC 276 ms
4,380 KB
testcase_23 AC 175 ms
4,380 KB
testcase_24 AC 216 ms
4,380 KB
testcase_25 AC 105 ms
4,380 KB
testcase_26 AC 245 ms
4,384 KB
testcase_27 AC 208 ms
4,380 KB
testcase_28 AC 109 ms
4,380 KB
testcase_29 AC 104 ms
4,380 KB
testcase_30 AC 85 ms
4,384 KB
testcase_31 AC 120 ms
4,380 KB
testcase_32 AC 15 ms
4,380 KB
testcase_33 AC 41 ms
4,380 KB
testcase_34 AC 59 ms
4,380 KB
testcase_35 AC 43 ms
4,380 KB
testcase_36 AC 181 ms
4,380 KB
testcase_37 AC 266 ms
4,380 KB
testcase_38 AC 97 ms
4,384 KB
testcase_39 AC 241 ms
4,380 KB
testcase_40 AC 56 ms
4,380 KB
testcase_41 AC 94 ms
4,384 KB
testcase_42 AC 358 ms
4,444 KB
testcase_43 AC 360 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

struct Vec {
  using etype = long long;  // type of elements
  using ptype = long long;  // type of product results
  etype x = 0, y = 0;
  constexpr Vec operator-() const { return {-x, -y}; }
  friend constexpr Vec operator+(const Vec& a, const Vec& b) { return {a.x + b.x, a.y + b.y}; }
  friend constexpr Vec operator-(const Vec& a, const Vec& b) { return {a.x - b.x, a.y - b.y}; }
  friend constexpr ptype operator*(const Vec& a, const Vec& b) { return (ptype)a.x * b.y - (ptype)a.y * b.x; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator*(T c, const Vec& a) { return {c * a.x, c * a.y}; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator*(const Vec& a, T c) { return c * a; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator/(const Vec& a, T c) { return {a.x / c, a.y / c}; }
  Vec& operator+=(const Vec& a) { x += a.x; y += a.y; return *this; }
  Vec& operator-=(const Vec& a) { x -= a.x; y -= a.y; return *this; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  Vec& operator*=(T c) { x *= c; y *= c; return *this; }
  friend constexpr bool operator==(const Vec& a, const Vec& b) { return a.x == b.x && a.y == b.y; }
  friend constexpr bool operator!=(const Vec& a, const Vec& b) { return !(a == b); }
  constexpr int quadrant() const { return y > 0 ? (x > 0 ? 0 : 1) : y < 0 ? (x < 0 ? 2 : 3) : (x > 0 ? 0 : x < 0 ? 2 : -1); }
  friend constexpr bool operator<(const Vec& a, const Vec& b) {
    int qa = a.quadrant(), qb = b.quadrant();
    if (qa != qb) return qa < qb;
    ptype p1 = (ptype)a.x * b.y, p2 = (ptype)a.y * b.x;
    return p1 > p2 || (p1 == p2 && (a.x != 0 ? abs(a.x) < abs(b.x) : abs(a.y) < abs(b.y)));
  }
  friend constexpr bool operator>(const Vec& a, const Vec& b) { return b < a; }
  friend constexpr bool operator<=(const Vec& a, const Vec& b) { return !(b < a); }
  friend constexpr bool operator>=(const Vec& a, const Vec& b) { return !(a < b); }
  constexpr int ccw(const Vec& u, const Vec& v) const { ptype p = (u - *this) * (v - *this); return p > 0 ? 1 : p < 0 ? -1 : 0; }
  static constexpr bool intersects(const Vec& a, const Vec& b, const Vec& c, const Vec& d) { return a.ccw(b, c) * a.ccw(b, d) <= 0 && c.ccw(d, a) * c.ccw(d, b) <= 0; }
  constexpr bool parallel_to(const Vec& a) const { return (ptype)x * a.y == (ptype)y * a.x; }
  constexpr ptype dot(const Vec& a) const { return (ptype)x * a.x + (ptype)y * a.y; }
  constexpr ptype norm2() const { return (ptype)x * x + (ptype)y * y; }
  constexpr bool is_zero() const { return x == 0 && y == 0; }
  constexpr Vec normalize() const {
    if (x == 0) return Vec{0, (y == 0 ? 0 : 1)};
    etype g = gcd(x, y);
    return *this / (x > 0 ? g : -g);
  }
  constexpr Vec rot90() const { return {-y, x}; }
  // exclusive
  constexpr bool in_between(const Vec& a, const Vec& b) const {
    Vec x = a - *this, y = b - *this;
    return x.parallel_to(y) && x.dot(y) < 0;
  }
  friend std::ostream& operator<< (std::ostream& os, const Vec& t) { return os << t.x << ' ' << t.y; }
  friend std::istream& operator>> (std::istream& os, Vec& t) { return os >> t.x >> t.y; }
};

double dist[300][300];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<Vec> v(2 * n);
  rep(i, 2 * n) cin >> v[i];
  rep(i, 2 * n) rep(j, 2 * n) dist[i][j] = 1e18;
  rep(i, 2 * n) rep(j, 2 * n) {
    if ((i ^ j) <= 1) continue;
    Vec x = v[i], y = v[j];
    bool ok = true;
    rep(idx, n) {
      Vec z = v[2 * idx], w = v[2 * idx + 1];
      if (((y - x) * (z - x)) * ((y - x) * (w - x)) < 0 &&
          ((w - z) * (x - z)) * ((w - z) * (y - z)) < 0) {
        ok = false;
        break;
      }
    }
    if (ok) dist[i][j] = sqrt((x - y).norm2());
  }
  rep(k, 2 * n) rep(i, 2 * n) rep(j, 2 * n) chmin(dist[i][j], dist[i][k] + dist[k][j]);
  cout << fixed << setprecision(12);
  rep(_, m) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int i = 2 * (a - 1) + b - 1;
    int j = 2 * (c - 1) + d - 1;
    cout << dist[i][j] << '\n';
  }
}
0