ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 28132 |
문제명 | 기벡을 안배운다고? |
레벨 | 골드 1 |
분류 |
기하학 |
시간복잡도 | O(nlogm) |
인풋사이즈 | n<=200,000, m<=10^9 |
사용한 언어 | Python 3.13 |
제출기록 | 72432KB / 480ms |
최고기록 | 364ms |
해결날짜 | 2025/02/18 |
"""Solution code for "BOJ 28132. 기벡을 안배운다고?".
- Problem link: https://www.acmicpc.net/problem/28132
- Solution link: http://www.teferi.net/ps/problems/boj/28132
Tags: [math]
"""
import collections
import math
import sys
def main():
N = int(sys.stdin.readline())
counter = collections.Counter()
zero_vec_count = 0
for _ in range(N):
x, y = [int(x) for x in sys.stdin.readline().split()]
if x == y == 0:
zero_vec_count += 1
else:
g = math.gcd(x, y)
counter[x // g, y // g] += 1
zero_nonzero_pair_count = zero_vec_count * (N - zero_vec_count)
zero_pair_count = zero_vec_count * (zero_vec_count - 1) // 2
nonzero_pair_count = sum(
count * counter[y, -x] for (x, y), count in counter.items()
)
answer = zero_nonzero_pair_count + zero_pair_count + nonzero_pair_count
print(answer)
if __name__ == '__main__':
main()