結果

問題 No.3005 トレミーの問題
ユーザー mkawa2
提出日時 2025-01-17 23:04:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 2,475 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2025-01-17 23:04:48
合計ジャッジ時間 2,590 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

# (x1,y1),(x2,y2)を通る直線ax+by+c=0
from math import gcd
from fractions import Fraction

# t=0 2点
# t=1 傾き分子、傾き分母(0可)、1点
class Line:
    def __init__(self, x1, y1, x2, y2, t=0):
        a, b, c = y2-y1, x1-x2, x2*y1-x1*y2
        if t: a, b, c = t*x1, -t*y1, y1*y2-x1*x2
        if a < 0: a, b, c = -a, -b, -c
        g = gcd(a, gcd(b, c))
        self.a, self.b, self.c = a//g, b//g, c//g

    def __eq__(self, other):
        return self.a == other.a and self.b == other.b and self.c == other.c

    def online(self, x, y):
        return self.a*x+self.b*y+self.c == 0

    # 交点の座標(分数)
    def crossf(self, other):
        if self == other: return "same", "same"
        if self.a*other.b == self.b*other.a: return "none", "none"
        return Fraction(self.c*other.b-self.b*other.c, self.b*other.a-self.a*other.b), Fraction(
            self.c*other.a-self.a*other.c, self.a*other.b-self.b*other.a)

    # 交点の座標(実数)
    def crossr(self, other):
        if self == other: return "same", "same"
        if self.a*other.b == self.b*other.a: return "none", "none"
        return (self.c*other.b-self.b*other.c)/(self.b*other.a-self.a*other.b), (self.c*other.a-self.a*other.c)/(
                self.a*other.b-self.b*other.a)

def ok():
    xy = LLI(4)
    ll = []
    for i in range(2):
        x, y = xy[i]
        s, t = xy[i+1]
        dx = s-x
        dy = t-y
        l = Line(dx, -dy, x+s, y+t, 2)
        ll.append(l)

    m, n = ll[0].crossf(ll[1])
    if m == "none": return False
    x, y = xy[-1]
    d = (m-x)**2+(n-y)**2
    for x, y in xy:
        if (m-x)**2+(n-y)**2 != d: return False
    return True

print("YES" if ok() else "NO")
0