結果

問題 No.461 三角形はいくつ?
ユーザー titiatitia
提出日時 2023-09-19 04:15:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,723 ms / 5,000 ms
コード長 1,342 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 79,736 KB
最終ジャッジ日時 2023-09-19 04:15:39
合計ジャッジ時間 27,608 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
72,980 KB
testcase_01 AC 122 ms
72,732 KB
testcase_02 AC 129 ms
72,528 KB
testcase_03 AC 121 ms
72,944 KB
testcase_04 AC 136 ms
77,480 KB
testcase_05 AC 608 ms
78,912 KB
testcase_06 AC 440 ms
78,916 KB
testcase_07 AC 451 ms
78,840 KB
testcase_08 AC 356 ms
78,820 KB
testcase_09 AC 163 ms
77,548 KB
testcase_10 AC 221 ms
78,560 KB
testcase_11 AC 488 ms
78,796 KB
testcase_12 AC 311 ms
79,024 KB
testcase_13 AC 654 ms
79,128 KB
testcase_14 AC 641 ms
79,248 KB
testcase_15 AC 642 ms
79,124 KB
testcase_16 AC 172 ms
79,072 KB
testcase_17 AC 172 ms
79,084 KB
testcase_18 AC 916 ms
79,032 KB
testcase_19 AC 964 ms
79,012 KB
testcase_20 AC 685 ms
78,944 KB
testcase_21 AC 638 ms
79,736 KB
testcase_22 AC 661 ms
79,160 KB
testcase_23 AC 255 ms
79,028 KB
testcase_24 AC 246 ms
79,048 KB
testcase_25 AC 1,591 ms
78,988 KB
testcase_26 AC 1,581 ms
78,960 KB
testcase_27 AC 156 ms
78,668 KB
testcase_28 AC 159 ms
78,752 KB
testcase_29 AC 1,633 ms
78,808 KB
testcase_30 AC 1,723 ms
78,972 KB
testcase_31 AC 1,552 ms
78,920 KB
testcase_32 AC 1,485 ms
78,928 KB
testcase_33 AC 156 ms
78,808 KB
testcase_34 AC 156 ms
78,872 KB
testcase_35 AC 149 ms
78,580 KB
testcase_36 AC 338 ms
79,236 KB
testcase_37 AC 322 ms
79,112 KB
testcase_38 AC 329 ms
79,272 KB
testcase_39 AC 302 ms
79,612 KB
testcase_40 AC 336 ms
79,112 KB
testcase_41 AC 353 ms
79,096 KB
testcase_42 AC 693 ms
79,184 KB
testcase_43 AC 764 ms
79,288 KB
testcase_44 AC 675 ms
79,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from bisect import bisect_left
from collections import Counter
from math import gcd

L=[[(0,1)] for i in range(3)]

N=int(input())

for i in range(N):
    p,a,b=map(int,input().split())
    G=gcd(a,b)
    L[p].append((b//G,(a+b)//G))

from functools import cmp_to_key

def cmp(a, b):
    if a[0]*b[1]>b[0]*a[1]:
        return 1
    elif a[0]*b[1]==b[0]*a[1]:
        return 0
    else:
        return -1

L[0].sort(key=cmp_to_key(cmp))
L[1].sort(key=cmp_to_key(cmp))
L[2].sort(key=cmp_to_key(cmp))

ANS=0
C=Counter(L[2])

for x0,x1 in L[0]:
    for y0,y1 in L[1]:
        if x0*y1+x1*y0>x1*y1:
            break

        if x0*y1>x1*y0:
            MAX=(x0,x1)
        else:
            MAX=(y0,y1)

        m0,m1=MAX

        OK=-1
        NG=len(L[2])

        while NG>OK+1:
            mid=(OK+NG)//2

            z0,z1=L[2][mid]

            if z0*m1<=(m1-m0)*z1:
                OK=mid
            else:
                NG=mid

        #print(x0,x1,y0,y1,L[2],OK)

        ANS+=OK+1
        z0=x0*y1+x1*y0
        z1=x1*y1
        G=gcd(z0,z1)
        z0//=G
        z1//=G

        #print((z1-z0,z1),z0*m1,(m1-m0)*z1)
        
        if (z1-z0)*m1<=(m1-m0)*z1 and (z1-z0,z1) in C:
            ANS-=C[(z1-z0,z1)]

            #print("!",x0,x1,y0,y1,MAX,z0,z1,C[(z0,z1)])

print(ANS)


        

0