結果

問題 No.2602 Real Collider
ユーザー nono00nono00
提出日時 2024-01-13 00:17:52
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,302 bytes
コンパイル時間 3,956 ms
コンパイル使用メモリ 269,248 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-28 00:38:08
合計ジャッジ時間 26,169 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 244 ms
6,944 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 312 ms
6,944 KB
testcase_17 AC 335 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 321 ms
6,940 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 130 ms
6,940 KB
testcase_27 WA -
testcase_28 AC 225 ms
6,944 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 269 ms
6,944 KB
testcase_35 WA -
testcase_36 AC 131 ms
6,944 KB
testcase_37 AC 409 ms
6,940 KB
testcase_38 AC 354 ms
6,940 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 290 ms
6,940 KB
testcase_43 AC 227 ms
6,940 KB
testcase_44 AC 443 ms
6,940 KB
testcase_45 AC 220 ms
6,944 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 257 ms
6,944 KB
testcase_49 WA -
testcase_50 AC 160 ms
6,940 KB
testcase_51 WA -
testcase_52 AC 112 ms
6,940 KB
testcase_53 AC 384 ms
6,940 KB
testcase_54 AC 227 ms
6,940 KB
testcase_55 AC 263 ms
6,944 KB
testcase_56 WA -
testcase_57 AC 234 ms
6,940 KB
testcase_58 AC 85 ms
6,940 KB
testcase_59 AC 358 ms
6,940 KB
testcase_60 AC 182 ms
6,944 KB
testcase_61 AC 186 ms
6,944 KB
testcase_62 AC 306 ms
6,940 KB
testcase_63 AC 309 ms
6,944 KB
testcase_64 WA -
testcase_65 AC 188 ms
6,940 KB
testcase_66 WA -
testcase_67 AC 143 ms
6,940 KB
testcase_68 AC 166 ms
6,944 KB
testcase_69 AC 106 ms
6,940 KB
testcase_70 AC 145 ms
6,944 KB
testcase_71 WA -
testcase_72 AC 289 ms
6,940 KB
testcase_73 AC 260 ms
6,940 KB
testcase_74 WA -
testcase_75 AC 335 ms
6,944 KB
testcase_76 WA -
testcase_77 AC 301 ms
6,940 KB
testcase_78 WA -
testcase_79 AC 293 ms
6,944 KB
testcase_80 AC 326 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i128 = __int128_t;

int sign(i128 a) {
    return a > 0 ? 1 : a < 0 ? -1 : 0;
}

i128 gcd(i128 lhs, i128 rhs) {
    if (rhs == 0) {
        return lhs;
    }
    return gcd(rhs, lhs % rhs);
}

i128 lcm(i128 lhs, i128 rhs) {
    return lhs / gcd(lhs, rhs) * rhs;
}

std::ostream& operator<<(std::ostream& os, i128 a) {
    int s = sign(a);
    a *= s;
    std::vector<char> b;
    while (a > 0) {
        b.push_back((char)(a % 10 + '0'));
        a /= 10;
    }
    if (s < 0) b.push_back('-');
    std::ranges::reverse(b);
    if (b.empty()) b.push_back('0');
    for (auto c: b) {
        os << c;
    }
    return os;
}

const i128 INF = 1e9;

struct Qu {
    i128 a, b;
    Qu(): a(0), b(0) {}
    Qu(i128 a_, i128 b_): a(a_), b(b_) {
        if (b == 0) {
            a = INF;
            b = 0;
        } else if (a != 0) {
            i128 g = gcd(sign(a) * a, sign(b) * b);
            a /= g;
            b /= g;

            if (sign(a) != sign(b)) {
                if (b < 0) {
                    a = -a;
                    b = -b;
                }
            } else if (a < 0) {
                a = -a;
                b = -b;
            }

        } else {
            b = 1;
        }
    }
    Qu(i128 v): Qu(v, 1) {}
};

std::ostream& operator<<(std::ostream& os, Qu q) {
    os << q.a << '/' << q.b;
    return os;
}

Qu operator+(Qu lhs, Qu rhs) {
    i128 b = lhs.b * rhs.b;
    i128 a = lhs.a * rhs.b + rhs.a * lhs.b;
    return Qu(a, b);
}

Qu operator-(Qu lhs, Qu rhs) {
    i128 b = lhs.b * rhs.b;
    i128 a = lhs.a * rhs.b - rhs.a * lhs.b;
    return Qu(a, b);
}

Qu operator*(Qu lhs, Qu rhs) {
    return Qu(lhs.a * rhs.a, lhs.b * rhs.b);
}

Qu operator/(Qu lhs, Qu rhs) {
    return Qu(lhs.a * rhs.b, lhs.b * rhs.a);
}

bool eq(Qu lhs, Qu rhs) {
    return lhs.a == rhs.a && lhs.b == rhs.b;
}

bool lt(Qu lhs, Qu rhs) {
    if (sign(lhs.a) != sign(rhs.a)) return sign(lhs.a) < sign(rhs.a);
    if (lhs.a / lhs.b == rhs.a / rhs.b) return sign(lhs.a) * lhs.a % lhs.b <= sign(rhs.a) * rhs.a % rhs.b;
    return lhs.a / lhs.b <= rhs.a / rhs.b;
}

struct Point {
    Point() {}
    Point(Qu x, Qu y): x(x), y(y) {}
    Qu x, y;
};

Point mid_point(Point lhs, Point rhs) {
    return Point((lhs.x + rhs.x) / 2, (lhs.y + rhs.y) / 2);
}

const Qu UNDEF(INF, 0);

struct Line {
    Qu coef;
    Qu constant;
    Line() {}
    Line(Qu coe, Qu con): coef(coe), constant(con) {}
    Line(Qu coef, Point point): coef(coef), constant(point.y - point.x * coef) {}
};

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

struct Circle {
    Point center;
    Qu radius;
    Circle(Point p, Qu r): center(p), radius(r) {}
};

bool inside(Circle circle, Point point) {
    return lt(distance(circle.center, point), circle.radius);
}

void solve() {
    int q;
    std::cin >> q;
    std::vector<Point> points(3);
    for (int i = 0; i < 3; i++) {
        int x, y;
        std::cin >> x >> y;
        points[i] = Point(Qu(x), Qu(y));
    }
    std::vector<Line> lines(2);
    for (int i = 0; i < 2; i++) {
        if (eq(points[i].y, points[i + 1].y)) {
            Point mid = mid_point(points[i], points[i + 1]);
            lines[i] = Line(UNDEF, mid.x);
        } else {
            Qu coef = (points[i + 1].x - points[i].x) / (points[i].y - points[i + 1].y);
            Point mid = mid_point(points[i], points[i + 1]);
            lines[i] = Line(coef, mid);
        }
    }

    Point center;
    if (eq(lines[0].coef, lines[1].coef)) {
        Qu min_dist = UNDEF;
        for (int i = 0; i < 3; i++) {
            for (int j = i + 1; j < 3; j++) {
                Point mid = mid_point(points[i], points[j]);
                Qu dist(0);
                for (int k = 0; k < 3; k++) {
                    Qu d = distance(mid, points[k]);
                    if (lt(dist, d)) {
                        dist = d;
                    }
                }
                if (eq(min_dist, UNDEF) || lt(dist, min_dist)) {
                    min_dist = dist;
                    center = mid;
                }
            }
        }
    } else {
        if (eq(lines[0].coef, UNDEF) || eq(lines[1].coef, UNDEF)) {
            if (eq(lines[0].coef, UNDEF)) std::swap(lines[0], lines[1]);
            center.x = lines[1].constant;
            center.y = lines[0].coef * center.x + lines[0].constant;
        } else {
            center.x = (lines[1].constant - lines[0].constant) / (lines[0].coef - lines[1].coef);
            center.y = (lines[0].coef * lines[1].constant - lines[0].constant * lines[1].coef)
                       / (lines[0].coef - lines[1].coef);
        }

        Qu d = distance(points[0], center);

        for (int i = 1; i < 3; i++) {}
    }

    Qu radius = 0;
    for (int i = 0; i < 3; i++) {
        Qu r = distance(center, points[i]);

        if (lt(radius, r)) {
            radius = r;
        }
    }

    Circle circle(center, radius);
    while (q--) {
        int x, y;
        std::cin >> x >> y;
        Point p(x, y);
        std::cout << (inside(circle, p) ? "Yes" : "No") << '\n';
    }
}

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

    while (t--) solve();
}
0