結果

問題 No.2769 Number of Rhombi
ユーザー hahho
提出日時 2024-05-10 22:17:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 952 ms / 5,000 ms
コード長 606 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 244,340 KB
最終ジャッジ日時 2024-12-20 05:57:59
合計ジャッジ時間 26,772 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations
from math import gcd
from collections import defaultdict

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

for (x0,y0),(x1,y1) in combinations(points, 2):
    dx = x1-x0
    dy = y1-y0
    if dx == 0:
        dy = 1
    elif dy == 0:
        dx = 1
    else:
        d = gcd(dx, dy)*(-1 if dx < 0 else 1)
        dx //= d
        dy //= d
    mids[x0+x1, y0+y1, dx, dy] += 1

res = 0
for (mx, my, dx, dy), cnt in mids.items():
    if dy <= 0:
        continue
    res += cnt*mids.get((mx, my, dy, -dx), 0)
print(res)
0