結果

問題 No.2628 Shrinkage
ユーザー nono00nono00
提出日時 2024-02-16 23:12:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,446 bytes
コンパイル時間 9,822 ms
コンパイル使用メモリ 465,196 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-02-16 23:13:50
合計ジャッジ時間 8,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    }
    if (dist(points[0], points[1]) <= dist(points[2], points[3])) {
        std::cout << "No" << '\n';
        return;
    }
    Line l1(points[0], points[1]);
    Line l2(points[2], points[3]);
    bool ok = false;
    if (!l1.valid && !l2.valid) {
        ok = true;
    } else if (l1.valid && l2.valid) {
        ok = (l1.m == l2.m);
    }
    if (!ok) {
        std::cout << "No" << '\n';
        return;
    }
    auto [f, c] = intersect(Line(points[0], points[2]), Line(points[1], points[3]));
    if (dist(points[0], c) < dist(points[0], points[2]) || dist(points[1], c) < dist(points[1], points[3])) {
        std::cout << "No" << '\n';
    } else {
        std::cout << "Yes" << '\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