結果

問題 No.2376 障害物競プロ
ユーザー 259-Momone
提出日時 2024-03-19 21:48:19
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,009 ms / 4,000 ms
コード長 2,452 bytes
コンパイル時間 4,436 ms
コンパイル使用メモリ 328,064 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-09-30 05:45:39
合計ジャッジ時間 63,822 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/extc++.h>
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
os << "[" << p.first << " " << p.second << "]";
return os;
}
int main() {
using namespace std;
unsigned N, M;
cin >> N >> M;
using point = pair<unsigned long, unsigned long>;
vector<pair<point, point>> segments(N);
for (auto &&[p1, p2] : segments) {
auto &&[x1, y1]{p1};
auto &&[x2, y2]{p2};
long a, b, c, d;
cin >> a >> b >> c >> d;
x1 = a + 10000;
y1 = b + 10000;
x2 = c + 10000;
y2 = d + 10000;
}
vector distances(2 * N, vector<long double>(2 * N, sqrt(numeric_limits<long double>::max())));
const auto side{[](const auto &p, const auto &segment) {
const auto &[x, y]{p};
const auto &[p1, p2]{segment};
const auto &[x1, y1]{p1};
const auto &[x2, y2]{p2};
const auto positive_part{x1 * y2 + x2 * y + x * y1};
const auto negative_part{x2 * y1 + x * y2 + x1 * y};
return (positive_part > negative_part) - (positive_part < negative_part);
}};
for (unsigned i{}; i < 2 * N; ++i) {
const auto &p1{i & 1 ? segments[i / 2].second : segments[i / 2].first};
for (unsigned j{}; j < 2 * N; ++j) {
const auto &p2{j & 1 ? segments[j / 2].second : segments[j / 2].first};
if (ranges::all_of(segments, [&side, &p1, &p2](const auto &s) {
auto x{side(p1, s)}, y{side(p2, s)};
auto t{side(s.first, make_pair(p1, p2))}, u{side(s.second, make_pair(p1, p2))};
if (x * y + 1 == 0 && t * u + 1 == 0)
return false;
return true;
}))
distances[i][j] = hypot(static_cast<long double>(p1.first) - p2.first, static_cast<long double>(p1.second) - p2.second);
}
}
for (unsigned _{}; _ < 3; ++_)
for (unsigned k{}; k < 2 * N; ++k)
for (unsigned i{}; i < 2 * N; ++i)
for (unsigned j{}; j < 2 * N; ++j)
distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j]);
cout << fixed << setprecision(15);
for (unsigned i{}, a, b, c, d; i < M; ++i) {
cin >> a >> b >> c >> d;
--a;
--b;
--c;
--d;
cout << distances[a * 2 + b][c * 2 + d] << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0