結果

問題 No.2769 Number of Rhombi
ユーザー ああいい
提出日時 2024-06-01 17:09:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,299 ms / 5,000 ms
コード長 1,056 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 347,912 KB
最終ジャッジ日時 2024-12-22 03:50:53
合計ジャッジ時間 57,651 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

point = []
for _ in range(N):
    x,y = map(int,input().split())
    point.append((x,y))

def gcd(a,b):
    if b == 0:return a
    r = a % b
    a = b
    b = r
    return gcd(a,b)

from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)

ans = 0

for i in range(N):
    x,y = point[i]
    for j in range(i + 1,N):
        xx,yy = point[j]

        if xx == x:
            u = (0,1)
        elif yy == y:
            u = (1,0)
        elif xx > x:
            a = xx - x
            b = yy - y
            t = gcd(a,b if b > 0 else -b)
            u = (a // t,b // t)
        else:
            a = x - xx
            b = y - yy
            t = gcd(a,b if b > 0 else -b)
            u = (a // t,b // t)
        v = (x + xx,y + yy)

        """
        ans += d1[v]
        ans -= d2[(v,u)]
        d1[v] += 1
        d2[(v,u)] += 1
        """

        m,mm = u
        uu = (-mm,m)
        uuu = (mm,-m)
        ans += d2[(v,uu)]
        ans += d2[(v,uuu)]
        d2[(v,u)] += 1
        
print(ans)
#print(d1,d2)
0