結果

問題 No.947 ABC包囲網
ユーザー 👑 tamatotamato
提出日時 2019-12-10 18:37:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,367 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 77,540 KB
最終ジャッジ日時 2023-09-06 07:22:08
合計ジャッジ時間 7,598 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,760 KB
testcase_01 AC 74 ms
71,672 KB
testcase_02 AC 76 ms
71,900 KB
testcase_03 AC 77 ms
71,536 KB
testcase_04 AC 75 ms
71,592 KB
testcase_05 AC 74 ms
71,184 KB
testcase_06 AC 74 ms
71,768 KB
testcase_07 AC 72 ms
71,760 KB
testcase_08 AC 72 ms
71,464 KB
testcase_09 AC 74 ms
71,280 KB
testcase_10 AC 74 ms
71,008 KB
testcase_11 AC 76 ms
71,624 KB
testcase_12 AC 75 ms
71,552 KB
testcase_13 AC 77 ms
71,672 KB
testcase_14 AC 74 ms
71,764 KB
testcase_15 AC 76 ms
71,952 KB
testcase_16 AC 74 ms
71,892 KB
testcase_17 AC 76 ms
71,912 KB
testcase_18 AC 76 ms
71,740 KB
testcase_19 AC 77 ms
71,720 KB
testcase_20 AC 76 ms
71,692 KB
testcase_21 AC 76 ms
71,620 KB
testcase_22 AC 76 ms
71,808 KB
testcase_23 AC 77 ms
71,552 KB
testcase_24 AC 74 ms
71,548 KB
testcase_25 AC 77 ms
71,596 KB
testcase_26 AC 76 ms
71,532 KB
testcase_27 AC 73 ms
71,532 KB
testcase_28 AC 88 ms
77,080 KB
testcase_29 AC 96 ms
77,036 KB
testcase_30 AC 91 ms
77,192 KB
testcase_31 AC 104 ms
77,228 KB
testcase_32 AC 105 ms
77,360 KB
testcase_33 AC 103 ms
77,376 KB
testcase_34 AC 102 ms
77,376 KB
testcase_35 AC 103 ms
77,220 KB
testcase_36 AC 103 ms
77,352 KB
testcase_37 AC 102 ms
77,400 KB
testcase_38 AC 104 ms
77,172 KB
testcase_39 AC 105 ms
77,204 KB
testcase_40 AC 102 ms
77,392 KB
testcase_41 AC 106 ms
77,068 KB
testcase_42 AC 105 ms
77,244 KB
testcase_43 AC 104 ms
77,264 KB
testcase_44 AC 103 ms
77,540 KB
testcase_45 AC 102 ms
77,180 KB
testcase_46 AC 103 ms
77,120 KB
testcase_47 AC 106 ms
77,180 KB
testcase_48 AC 106 ms
77,168 KB
testcase_49 AC 102 ms
77,132 KB
testcase_50 AC 105 ms
77,108 KB
testcase_51 AC 82 ms
71,540 KB
testcase_52 AC 77 ms
71,620 KB
testcase_53 AC 78 ms
71,592 KB
testcase_54 AC 76 ms
71,740 KB
testcase_55 AC 76 ms
71,860 KB
testcase_56 AC 74 ms
71,764 KB
testcase_57 AC 76 ms
71,864 KB
testcase_58 AC 77 ms
71,588 KB
testcase_59 AC 76 ms
71,588 KB
権限があれば一括ダウンロードができます

ソースコード

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