結果

問題 No.1041 直線大学
コンテスト
ユーザー はむ吉🐹
提出日時 2020-05-01 21:57:51
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 1,078 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 163 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 92,316 KB
最終ジャッジ日時 2026-05-11 12:58:41
合計ジャッジ時間 9,017 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/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