結果

問題 No.1041 直線大学
ユーザー nephrologist
提出日時 2020-05-01 23:54:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-11-16 07:58:48
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from collections import defaultdict, Counter

n = int(input())
XY = []
for i in range(n):
    x, y = map(int, input().split())
    XY.append((x, y))


def line_calc(x1, y1, x2, y2):
    return -(y1 - y2), (x1 - x2), y1 * (x1 - x2) - x1 * (y1 - y2)


def check_line(a, b, c, x, y):
    return a * x + b * y == c


if n == 2:
    print(2)
else:
    line = []
    for i in range(n - 1):
        for j in range(i + 1, n):
            x1, y1 = XY[i]
            x2, y2 = XY[j]
            line.append(line_calc(x1, y1, x2, y2))
    ans = 0
    for pair in line:
        cnt = 0
        a, b, c = pair
        for x, y in XY:
            if check_line(a, b, c, x, y):
                cnt += 1
        ans = max(cnt, ans)
    print(ans)
0