結果
| 問題 |
No.1041 直線大学
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:17:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 2,000 ms |
| コード長 | 1,088 bytes |
| コンパイル時間 | 344 ms |
| コンパイル使用メモリ | 82,912 KB |
| 実行使用メモリ | 75,168 KB |
| 最終ジャッジ日時 | 2025-03-20 21:18:42 |
| 合計ジャッジ時間 | 3,732 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
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)
lam6er