結果

問題 No.947 ABC包囲網
ユーザー tamatotamato
提出日時 2019-12-10 18:37:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,367 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 82,972 KB
実行使用メモリ 70,016 KB
最終ジャッジ日時 2024-06-24 02:04:57
合計ジャッジ時間 5,070 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import atan, pi
import sys
input = sys.stdin.buffer.readline


def atan_(val):
    ret = atan(val)
    if ret >= 0:
        return ret
    else:
        return ret + pi


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

P = []
n_pos = 0
for x, y in points:
    if y > 0:
        n_pos += 1
        if x == 0:
            P.append((pi / 2, 1))
        else:
            P.append((atan_(y / x), 1))
    elif y < 0:
        if x == 0:
            P.append((pi / 2, -1))
        else:
            P.append((atan_(y / x), -1))
    else:
        if x > 0:
            n_pos += 1
            P.append((0, 1))
        else:
            P.append((0, -1))
n_neg = N - n_pos

P.sort(key=lambda p: p[0])
pos = 0
neg = 0
prev = -1
tmp_pos = 0
tmp_neg = 0
ans = 0
for rad, pn in P:
    if rad != prev:
        ans += tmp_pos * neg * (n_neg - neg - tmp_neg)
        ans += tmp_neg * pos * (n_pos - pos - tmp_pos)
        pos += tmp_pos
        neg += tmp_neg
        prev = rad
        if pn == 1:
            tmp_pos = 1
            tmp_neg = 0
        else:
            tmp_pos = 0
            tmp_neg = 1
    else:
        if pn == 1:
            tmp_pos += 1
        else:
            tmp_neg += 1

ans += tmp_pos * neg * (n_neg - neg - tmp_neg)
ans += tmp_neg * pos * (n_pos - pos - tmp_pos)

print(ans)
0