結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー しらっ亭しらっ亭
提出日時 2015-07-01 03:01:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 101 ms / 5,000 ms
コード長 727 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 8,740 KB
最終ジャッジ日時 2023-09-22 04:53:27
合計ジャッジ時間 1,092 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
8,740 KB
testcase_01 AC 101 ms
8,696 KB
testcase_02 AC 65 ms
8,652 KB
testcase_03 AC 98 ms
8,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import heapq


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

    h = [0, 0, 0]

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

    c = 0
    while h:
        n1 = heapq.heappop(h)
        n2 = heapq.heappop(h)
        n3 = heapq.heappop(h)

        if n3 == 0:
            break

        c += 1

        heapq.heappush(h, n1 + 1)
        heapq.heappush(h, n2 + 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