結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー lloyzlloyz
提出日時 2023-06-29 00:13:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 513 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 86,576 KB
実行使用メモリ 81,520 KB
最終ジャッジ日時 2023-09-19 05:05:43
合計ジャッジ時間 3,883 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from heapq import heapify, heappop, heappush

for _ in range(int(input())):
    n = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)
    H = [-cnt for cnt in counter.values()]
    heapify(H)
    ans = 0
    while len(H) >= 3:
        a = -heappop(H)
        b = -heappop(H)
        c = -heappop(H)
        ans += c
        a -= c
        if a > 0:
            heappush(H, -a)
        b -= c
        if b > 0:
            heappush(H, -b)
    print(ans)
0