結果

問題 No.947 ABC包囲網
ユーザー titiatitia
提出日時 2019-12-10 02:58:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 94,760 KB
最終ジャッジ日時 2023-09-05 18:43:51
合計ジャッジ時間 22,988 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 247 ms
89,612 KB
testcase_01 AC 244 ms
89,676 KB
testcase_02 AC 242 ms
89,632 KB
testcase_03 AC 245 ms
89,448 KB
testcase_04 AC 245 ms
89,628 KB
testcase_05 AC 242 ms
89,488 KB
testcase_06 AC 235 ms
89,516 KB
testcase_07 AC 240 ms
89,708 KB
testcase_08 AC 242 ms
89,544 KB
testcase_09 AC 241 ms
89,500 KB
testcase_10 AC 246 ms
89,644 KB
testcase_11 AC 246 ms
89,568 KB
testcase_12 AC 246 ms
89,624 KB
testcase_13 AC 243 ms
89,656 KB
testcase_14 AC 248 ms
89,648 KB
testcase_15 AC 294 ms
91,816 KB
testcase_16 AC 277 ms
90,672 KB
testcase_17 AC 281 ms
90,668 KB
testcase_18 AC 276 ms
90,940 KB
testcase_19 AC 276 ms
90,912 KB
testcase_20 AC 276 ms
90,668 KB
testcase_21 AC 274 ms
91,020 KB
testcase_22 AC 278 ms
90,820 KB
testcase_23 AC 281 ms
91,016 KB
testcase_24 AC 286 ms
91,148 KB
testcase_25 AC 279 ms
90,756 KB
testcase_26 AC 278 ms
90,732 KB
testcase_27 AC 281 ms
90,812 KB
testcase_28 AC 329 ms
92,716 KB
testcase_29 AC 399 ms
93,808 KB
testcase_30 AC 381 ms
94,056 KB
testcase_31 AC 398 ms
94,708 KB
testcase_32 AC 407 ms
94,500 KB
testcase_33 AC 401 ms
94,544 KB
testcase_34 AC 397 ms
94,176 KB
testcase_35 AC 416 ms
94,276 KB
testcase_36 AC 401 ms
94,680 KB
testcase_37 AC 397 ms
94,288 KB
testcase_38 AC 419 ms
94,620 KB
testcase_39 AC 421 ms
94,560 KB
testcase_40 AC 424 ms
94,760 KB
testcase_41 AC 424 ms
93,704 KB
testcase_42 AC 429 ms
94,172 KB
testcase_43 AC 419 ms
94,352 KB
testcase_44 AC 417 ms
94,468 KB
testcase_45 AC 404 ms
94,396 KB
testcase_46 AC 400 ms
94,676 KB
testcase_47 AC 400 ms
94,532 KB
testcase_48 AC 410 ms
94,428 KB
testcase_49 AC 404 ms
94,332 KB
testcase_50 AC 421 ms
94,616 KB
testcase_51 AC 264 ms
90,428 KB
testcase_52 AC 257 ms
90,684 KB
testcase_53 AC 256 ms
90,864 KB
testcase_54 AC 240 ms
89,448 KB
testcase_55 AC 245 ms
89,552 KB
testcase_56 AC 245 ms
89,436 KB
testcase_57 AC 283 ms
91,240 KB
testcase_58 AC 280 ms
91,216 KB
testcase_59 AC 280 ms
90,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import Fraction
import sys
input = sys.stdin.readline

n=int(input())
P=[tuple(map(int,input().split())) for i in range(n)]

Q0=[]
Q1=[]

for x,y in P:
    if x>0:
        Q1.append(Fraction(y,x))
    elif x==0:
        if y>0:
            Q1.append(float("inf"))
        else:
            Q0.append(float("inf"))

    else:
        Q0.append(Fraction(y,x))
        
Q0.sort()
Q1.sort()

ANS=0
import bisect

BQL0=[0]*len(Q0)
BQR0=[0]*len(Q0)

for i in range(len(Q0)):
    BQL0[i]=bisect.bisect_left(Q1,Q0[i])
    BQR0[i]=bisect.bisect_right(Q1,Q0[i])

for i in range(len(Q0)-1):
    for j in range(i+1,len(Q0)):
        ANS+=max(0,BQL0[j]-BQR0[i])

BQL1=[0]*len(Q1)
BQR1=[0]*len(Q1)

for i in range(len(Q1)):
    BQL1[i]=bisect.bisect_left(Q0,Q1[i])
    BQR1[i]=bisect.bisect_right(Q0,Q1[i])

for i in range(len(Q1)-1):
    for j in range(i+1,len(Q1)):
        ANS+=max(0,BQL1[j]-BQR1[i])
        
print(ANS)
0