結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-05-25 15:47:04 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 407 ms / 5,000 ms | 
| コード長 | 547 bytes | 
| コンパイル時間 | 457 ms | 
| コンパイル使用メモリ | 82,344 KB | 
| 実行使用メモリ | 79,504 KB | 
| 最終ジャッジ日時 | 2024-12-20 19:49:13 | 
| 合計ジャッジ時間 | 3,152 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
from collections import Counter
from heapq import *
def solve():
    N = int(input())
    L = list(map(int, input().split()))
    counter = Counter(L)
    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 += 1
        if a > 1:
            heappush(H, -a + 1)
        if b > 1:
            heappush(H, -b + 1)
        if c > 1:
            heappush(H, -c + 1)
    print(ans)
T = int(input())
for _ in range(T):
    solve()
            
            
            
        