結果

問題 No.1041 直線大学
ユーザー はむ吉🐹はむ吉🐹
提出日時 2020-05-01 21:57:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 714 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,592 KB
最終ジャッジ日時 2024-11-16 07:54:09
合計ジャッジ時間 13,023 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import fractions
import itertools


def compute(n, points):
    # (slope, intercept)
    usual_lines = dict()
    # x_0
    unusual_lines = dict()
    for (x1, y1), (x2, y2) in itertools.combinations(points, r=2):
        if x1 != x2:
            slope = fractions.Fraction(y1 - y2, x1 - x2)
            intercept = y1 - slope * x1
            usual_lines[(slope, intercept)] = 0
        else:
            unusual_lines[x1] = 0
    for x1, y1 in points:
        for slope, intercept in usual_lines:
            if y1 == slope * x1 + intercept:
                usual_lines[(slope, intercept)] += 1
        for x0 in unusual_lines:
            if x1 == x0:
                unusual_lines[x1] += 1
    res = 0
    if usual_lines:
        res = max(res, max(usual_lines.values()))
    if unusual_lines:
        res = max(res, max(unusual_lines.values()))
    return res


def main():
    n = int(input())
    points = [tuple(int(z) for z in input().split()) for _ in range(n)]
    res = compute(n, points)
    print(res)


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