結果

問題 No.2602 Real Collider
ユーザー strangerxxxstrangerxxx
提出日時 2024-05-01 18:35:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 856 ms / 2,000 ms
コード長 6,439 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 83,776 KB
最終ジャッジ日時 2024-05-01 18:36:13
合計ジャッジ時間 39,033 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,016 KB
testcase_01 AC 38 ms
53,888 KB
testcase_02 AC 38 ms
53,632 KB
testcase_03 AC 43 ms
55,296 KB
testcase_04 AC 38 ms
53,632 KB
testcase_05 AC 43 ms
54,272 KB
testcase_06 AC 38 ms
54,016 KB
testcase_07 AC 39 ms
53,888 KB
testcase_08 AC 38 ms
53,888 KB
testcase_09 AC 40 ms
54,144 KB
testcase_10 AC 856 ms
82,688 KB
testcase_11 AC 591 ms
81,484 KB
testcase_12 AC 247 ms
78,456 KB
testcase_13 AC 180 ms
77,480 KB
testcase_14 AC 262 ms
78,152 KB
testcase_15 AC 410 ms
79,616 KB
testcase_16 AC 582 ms
80,896 KB
testcase_17 AC 691 ms
81,408 KB
testcase_18 AC 203 ms
77,440 KB
testcase_19 AC 234 ms
77,780 KB
testcase_20 AC 625 ms
80,864 KB
testcase_21 AC 224 ms
78,452 KB
testcase_22 AC 222 ms
77,920 KB
testcase_23 AC 192 ms
77,668 KB
testcase_24 AC 247 ms
78,536 KB
testcase_25 AC 210 ms
77,668 KB
testcase_26 AC 257 ms
77,624 KB
testcase_27 AC 236 ms
78,448 KB
testcase_28 AC 333 ms
77,984 KB
testcase_29 AC 234 ms
78,188 KB
testcase_30 AC 255 ms
78,404 KB
testcase_31 AC 559 ms
80,000 KB
testcase_32 AC 531 ms
80,128 KB
testcase_33 AC 567 ms
80,640 KB
testcase_34 AC 664 ms
82,828 KB
testcase_35 AC 427 ms
79,232 KB
testcase_36 AC 258 ms
77,968 KB
testcase_37 AC 631 ms
79,872 KB
testcase_38 AC 630 ms
80,640 KB
testcase_39 AC 608 ms
80,384 KB
testcase_40 AC 369 ms
79,232 KB
testcase_41 AC 676 ms
81,152 KB
testcase_42 AC 561 ms
80,000 KB
testcase_43 AC 614 ms
82,168 KB
testcase_44 AC 675 ms
81,024 KB
testcase_45 AC 507 ms
80,852 KB
testcase_46 AC 481 ms
79,616 KB
testcase_47 AC 587 ms
81,024 KB
testcase_48 AC 553 ms
79,924 KB
testcase_49 AC 463 ms
79,488 KB
testcase_50 AC 412 ms
80,000 KB
testcase_51 AC 438 ms
79,360 KB
testcase_52 AC 330 ms
79,176 KB
testcase_53 AC 586 ms
80,640 KB
testcase_54 AC 481 ms
80,576 KB
testcase_55 AC 533 ms
80,560 KB
testcase_56 AC 529 ms
79,616 KB
testcase_57 AC 497 ms
80,560 KB
testcase_58 AC 377 ms
80,256 KB
testcase_59 AC 566 ms
80,640 KB
testcase_60 AC 372 ms
78,616 KB
testcase_61 AC 548 ms
80,768 KB
testcase_62 AC 624 ms
81,280 KB
testcase_63 AC 717 ms
83,388 KB
testcase_64 AC 671 ms
82,304 KB
testcase_65 AC 495 ms
81,468 KB
testcase_66 AC 599 ms
80,304 KB
testcase_67 AC 449 ms
80,516 KB
testcase_68 AC 478 ms
81,216 KB
testcase_69 AC 413 ms
81,516 KB
testcase_70 AC 414 ms
80,384 KB
testcase_71 AC 420 ms
79,616 KB
testcase_72 AC 586 ms
81,024 KB
testcase_73 AC 569 ms
81,536 KB
testcase_74 AC 578 ms
80,384 KB
testcase_75 AC 664 ms
81,280 KB
testcase_76 AC 541 ms
80,128 KB
testcase_77 AC 554 ms
81,024 KB
testcase_78 AC 630 ms
80,768 KB
testcase_79 AC 643 ms
81,960 KB
testcase_80 AC 710 ms
83,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


def resolve():
    import sys

    input = sys.stdin.readline
    q = int(input())
    xa, ya, xb, yb, xc, yc = map(int, input().split())
    x = (xa, ya)
    y = (xb, yb)
    z = (xc, yc)
    try:
        c = circumcenter2(x, y, z)
        d = distance(c, (xa, ya))
    except ZeroDivisionError:
        c = (0, 0)
        d = float("inf")
    da = (
        distance(x, y),
        distance(y, z),
        distance(z, x),
    )
    if da[0] >= da[1] + da[2]:
        c = center(x, y)
        d = distance(x, c)
    elif da[1] >= da[2] + da[0]:
        c = center(y, z)
        d = distance(y, c)
    elif da[2] >= da[0] + da[1]:
        c = center(z, x)
        d = distance(z, c)
    for _ in range(q):
        x, y = map(int, input().split())
        print("Yes" if distance(c, (x, y)) <= d else "No")


class Fraction:
    def __init__(self, a: int = 0, b: int = 1) -> None:
        if isinstance(a, Fraction):
            self.a, self.b = a.a, a.b
            return
        a, b = int(a), int(b)
        if b == 0:
            raise ZeroDivisionError(f"{a}/{b}")
        if b < 0:
            a, b = -a, -b
        self.a, self.b = a, b
        self._reducion()

    def _reducion(self):
        g = math.gcd(self.a, self.b)
        self.a //= g
        self.b //= g

    def __add__(self, other):
        if isinstance(other, Fraction):
            g = math.gcd(self.b, other.b)
            x = other.b // g * self.a
            y = self.b // g * other.a
            return Fraction(x + y, self.b // g * other.b)
        return Fraction(self.a + other * self.b, self.b)

    def __iadd__(self, other):
        if isinstance(other, Fraction):
            g = math.gcd(self.b, other.b)
            self.a *= other.b // g
            self.a += self.b // g * other.a
            self.b *= other.b // g
        else:
            self.a += other * self.b
        self._reducion()
        return self

    __radd__ = __add__

    def __sub__(self, other):
        if isinstance(other, Fraction):
            return self.__add__(-other)
        return self.__add__(-other)

    def __isub__(self, other):
        if isinstance(other, Fraction):
            return self.__iadd__(-other.a, other.b)
        return self.__iadd__(-other)

    def __rsub__(self, other):
        return -self + other

    def __mul__(self, other):
        if isinstance(other, Fraction):
            return Fraction(self.a * other.a, self.b * other.b)
        else:
            return Fraction(self.a * other, self.b)

    def __imul__(self, other):
        if isinstance(other, Fraction):
            self.a *= other.a
            self.b *= other.b
        else:
            self.a *= other
        self._reducion()
        return self

    __rmul__ = __mul__

    def __floordiv__(self, other):
        if isinstance(other, Fraction):
            return self.__mul__(other.inverse())
        return Fraction(self.a, self.b * other)

    def __ifloordiv__(self, other):
        if isinstance(other, Fraction):
            return self.__imul__(other.inverse())
        self.b *= other
        self._reducion()
        return self

    def __rfloordiv__(self, other):
        return self.inverse() * other

    __truediv__ = __floordiv__
    __itruediv__ = __ifloordiv__
    __rtruediv__ = __rfloordiv__

    def __pow__(self, other):
        if isinstance(other, Fraction):
            if other.b == 1:
                return self.__pow__(other.a)
            raise NotImplementedError
        return Fraction(self.a**other, self.b**other)

    def __ipow__(self, other):
        if isinstance(other, Fraction):
            if other.b == 1:
                return self.__ipow__(other.a)
            raise NotImplementedError
        self.a **= other
        self.b **= other
        return self

    def __rpow__(self, other):
        if self.b != 1:
            raise NotImplementedError
        return other**self.a

    def __floor__(self) -> int:
        return self.a // self.b

    def __ceil__(self) -> int:
        return (self.a + self.b - 1) // self.b

    __int__ = __floor__

    def __float__(self):
        return self.a / self.b

    def inverse(self):
        if self.a == 0:
            raise ZeroDivisionError(f"tring to calcuate inverse of {self.a}/{self.b}")
        return Fraction(self.b, self.a)

    def __pos__(self):
        return Fraction(self.a, self.b)

    def __neg__(self):
        return Fraction(-self.a, self.b)

    def __abs__(self):
        return Fraction(abs(self.a), self.b)

    def __eq__(self, other) -> bool:
        if isinstance(other, Fraction):
            return self.a == other.a and self.b == other.b
        return self.a == self.b * other

    def __gt__(self, other):
        if isinstance(other, Fraction):
            return self.a * other.b > other.a * self.b
        return self.a > self.b * other

    def __ge__(self, other):
        if isinstance(other, Fraction):
            return self.a * other.b >= other.a * self.b
        return self.a >= self.b * other

    def __lt__(self, other):
        if isinstance(other, Fraction):
            return self.a * other.b < other.a * self.b
        return self.a < self.b * other

    def __le__(self, other):
        if isinstance(other, Fraction):
            return self.a * other.b <= other.a * self.b
        return self.a <= self.b * other

    def __str__(self) -> str:
        return f"{self.a}/{self.b}"

    __repr__ = __str__

    def __hash__(self) -> int:
        return hash(self.__str__())


def distance(pa, pb):
    return sum([(i - j) ** 2 for i, j in zip(pa, pb)])


def islinear(pa, pb, pc):
    return (pa[0] - pb[0]) * (pa[1] - pc[1]) == (pa[0] - pc[0]) * (pa[1] - pb[1])


def center(x, y):
    return Fraction((x[0] + y[0]), 2), Fraction((x[1] + y[1]), 2)


def circumcenter2(pa, pb, pc):
    # 外心
    x0 = (
        (pa[0] ** 2 + pa[1] ** 2) * (pb[1] - pc[1])
        + (pb[0] ** 2 + pb[1] ** 2) * (pc[1] - pa[1])
        + (pc[0] ** 2 + pc[1] ** 2) * (pa[1] - pb[1])
    )
    y0 = 2 * ((pb[1] - pc[1]) * (pa[0] - pb[0]) - (pa[1] - pb[1]) * (pb[0] - pc[0]))
    x1 = (
        (pa[0] ** 2 + pa[1] ** 2) * (pb[0] - pc[0])
        + (pb[0] ** 2 + pb[1] ** 2) * (pc[0] - pa[0])
        + (pc[0] ** 2 + pc[1] ** 2) * (pa[0] - pb[0])
    )
    y1 = 2 * ((pb[0] - pc[0]) * (pa[1] - pb[1]) - (pa[0] - pb[0]) * (pb[1] - pc[1]))
    return Fraction(x0, y0), Fraction(x1, y1)


if __name__ == "__main__":
    resolve()
0