結果

問題 No.3128 Isosceles Triangle
ユーザー norioc
提出日時 2025-04-26 04:13:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 333 ms / 2,500 ms
コード長 762 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 82,480 KB
実行使用メモリ 174,280 KB
最終ジャッジ日時 2025-04-26 04:13:52
合計ジャッジ時間 7,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right
from collections import Counter
from math import comb


def find_interval(a: list, lo: int, hi: int) -> tuple[int, int, int]:
    """ソート済みリスト a の要素の lo 以上 hi 以下の個数と区間を返す
    return: 範囲内の個数, l, r
    """
    assert lo <= hi
    empty = 0, -1, -1  # 区間なし
    if not a or lo > a[-1] or hi < a[0]: return empty

    l = bisect_left(a, lo)
    r = bisect_right(a, hi) - 1
    if l > r: return empty
    return r-l+1, l, r


N = int(input())
A = list(map(int, input().split()))
A.sort()

freq = Counter(A)
ans = 0
for k, v in freq.items():
    if v < 2: continue

    cnt, _, _ = find_interval(A, 1, 2*k-1)
    ans += (cnt - v) * comb(v, 2)

print(ans)
0