結果

問題 No.461 三角形はいくつ?
ユーザー ヒッキープログラミングするスレ GitHub ガチ
提出日時 2016-12-12 02:06:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 994 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 185,184 KB
最終ジャッジ日時 2024-11-29 12:36:04
合計ジャッジ時間 133,269 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 18 WA * 12 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import Fraction
from bisect import bisect_left

n = int(input())

ps = [[Fraction(1)], [Fraction(1)], [Fraction(1)]]

for _ in range(n):
    p, a, b = map(int, input().split())
    ps[p].append(Fraction(a, a + b))

ps = sorted(map(sorted, ps), key=len, reverse=True)

ans = 0
for x in ps[0]:
    t = bisect_left(ps[1], Fraction(1) - x) 
    for c in range(t, len(ps[1])):
        y = ps[1][c]
        mn, mx = (x, y) if x < y else (y, x)
        k = Fraction(1) - mn
        i = bisect_left(ps[2], k)
        ans += len(ps[2]) - i
        if mn > Fraction(1, 2):
            r = (Fraction(1) - mn) + (Fraction(1) - mx)
            j = bisect_left(ps[2], r, i)
            if ps[2][j] == r:
                ans -= 1
        elif mn == Fraction(1) - mx:
            ans -= 1
        elif mn != mx:
            r = mn - (Fraction(1) - mx)
            j = bisect_left(ps[2], r, i)
            if ps[2][j] == r:
                ans -= 1
        else:
            ans -= 1

print(ans)
0