結果

問題 No.2628 Shrinkage
ユーザー nono00nono00
提出日時 2024-02-16 22:24:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,255 bytes
コンパイル時間 12,015 ms
コンパイル使用メモリ 464,340 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-16 22:25:14
合計ジャッジ時間 11,323 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
6,676 KB
testcase_24 WA -
testcase_25 RE -
testcase_26 AC 2 ms
6,676 KB
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>

using Real = boost::rational<boost::multiprecision::cpp_int>;

struct Point {
    Point() {}
    Real x = 0, y = 0;
};

bool operator==(Point lhs, Point rhs) {
    return lhs.x == rhs.x && lhs.y == rhs.y;
}

struct Line {
    Real m, c;
    bool valid = true;
    Line() {}
    Line(Point lhs, Point rhs) {
        if (lhs.x - rhs.x == 0) {
            valid = false;
            m = lhs.x;
        } else {
            m = (lhs.y - rhs.y) / (lhs.x - rhs.x);
            c = lhs.y - m * lhs.x;
        }
    }
};

std::pair<bool, Point> intersect(Line lhs, Line rhs) {
    if (!lhs.valid && !rhs.valid) return {false, Point()};
    if (!lhs.valid) {
        Point p;
        p.x = lhs.m;
        p.y = rhs.m * p.x + rhs.c;
        return {true, p};
    } else if (!rhs.valid) {
        Point p;
        p.x = rhs.m;
        p.y = lhs.m * p.x + lhs.c;
        return {true, p};
    }
    if (lhs.m == rhs.m) return {false, Point()};
    Point p;
    p.x = (lhs.c - rhs.c) / (rhs.m - lhs.m);
    p.y = lhs.m * p.x + lhs.c;
    return {true, p};
}

Real dist(Point lhs, Point rhs) {
    return (lhs.x - rhs.x) * (lhs.x - rhs.x) + (lhs.y - rhs.y) * (lhs.y - rhs.y);
}

void solve() {
    std::vector<Point> points(4);
    for (int i = 0; i < 4; i++) {
        long long x, y;
        std::cin >> x >> y;
        points[i].x = x;
        points[i].y = y;
    }
    if (points[0] == points[2] || points[1] == points[3]) {
        std::cout << "Yes" << '\n';
        return;
    }

    Line l1(points[0], points[2]);
    Line l2(points[1], points[3]);

    auto [f, c] = intersect(l1, l2);
    if (!f) {
        std::cout << "No" << '\n';
        return;
    }
    Real d1 = dist(points[0], c);
    Real d2 = dist(points[1], c);
    Real D1 = dist(points[0], points[2]);
    Real D2 = dist(points[1], points[3]);
    Real k1 = D1 / d1;
    Real k2 = D2 / d2;

    if (k1 == k2 && 0 < k1 && k1 < 1) {
        std::cout << "Yes" << '\n';
    } else {
        std::cout << "No" << '\n';
    }
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(16);
    int t = 1;
    std::cin >> t;
    while (t--) solve();
}
0