結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-06-29 00:13:33 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 513 bytes | 
| コンパイル時間 | 171 ms | 
| コンパイル使用メモリ | 82,116 KB | 
| 実行使用メモリ | 78,796 KB | 
| 最終ジャッジ日時 | 2024-07-05 17:32:12 | 
| 合計ジャッジ時間 | 2,175 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | WA * 4 | 
ソースコード
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)
            
            
            
        