結果

問題 No.1041 直線大学
ユーザー lam6er
提出日時 2025-03-20 19:03:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 75,536 KB
最終ジャッジ日時 2025-03-20 19:03:34
合計ジャッジ時間 3,533 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict

n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]

if n <= 1:
    print(n)
    exit()

max_res = 0

for i in range(n):
    xi, yi = points[i]
    slope_counts = defaultdict(int)
    for j in range(n):
        if i == j:
            continue
        xj, yj = points[j]
        dx = xj - xi
        dy = yj - yi
        
        g = math.gcd(abs(dx), abs(dy))
        if g == 0:
            dx_g = 0
            dy_g = 0
        else:
            dx_g = dx // g
            dy_g = dy // g
        
        # Normalize the direction
        if dx_g == 0:
            # Vertical line, ensure dy is positive
            if dy_g < 0:
                dy_g = -dy_g
        else:
            if dx_g < 0:
                dx_g = -dx_g
                dy_g = -dy_g
        
        slope = (dx_g, dy_g)
        slope_counts[slope] += 1
    
    current_max = 0
    if slope_counts:
        current_max = max(slope_counts.values())
    max_res = max(max_res, current_max + 1)  # include the current point i

print(max_res)
0