結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー しらっ亭
提出日時 2015-07-01 02:33:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-07-07 21:36:23
合計ジャッジ時間 861 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import heapq


def solve(N, L):
    c2 = Counter(Counter(L).values())

    h = []

    for n in sorted(c2.keys(), reverse=True):
        k = c2[n]
        for i in range(k):
            heapq.heappush(h, -n)

    c = 0
    while len(h) >= 3:
        c += 1
        n1 = heapq.heappop(h)
        n2 = heapq.heappop(h)
        n3 = heapq.heappop(h)

        if n1 < -1:
            heapq.heappush(h, n1 + 1)
        if n2 < -1:
            heapq.heappush(h, n2 + 1)
        if n3 < -1:
            heapq.heappush(h, n3 + 1)

    return c


def main():
    T = int(input())
    for t in range(T):
        N = int(input())
        L = list(map(int, input().split()))
        print(solve(N, L))


if __name__ == '__main__':
    main()
0