結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  FromBooska | 
| 提出日時 | 2023-05-19 16:56:14 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 510 ms / 5,000 ms | 
| コード長 | 612 bytes | 
| コンパイル時間 | 156 ms | 
| コンパイル使用メモリ | 82,452 KB | 
| 実行使用メモリ | 83,388 KB | 
| 最終ジャッジ日時 | 2024-12-17 23:46:26 | 
| 合計ジャッジ時間 | 3,238 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
from collections import Counter
from heapq import *
T = int(input())
for t in range(T):
    N = int(input())
    L = list(map(int, input().split()))
    H = []
    heapify(H)
    counted = Counter(L)
    for n in counted:
        heappush(H, (-counted[n], n))
    count = 0
    while len(H) >= 3:
        count += 1
        c1, n1 = heappop(H)
        c2, n2 = heappop(H)
        c3, n3 = heappop(H)
        if c1 < -1:
            heappush(H, (c1+1, n1))
        if c2 < -1:
            heappush(H, (c2+1, n2))    
        if c3 < -1:
            heappush(H, (c3+1, n3))    
        #print(H)
    print(count)
            
            
            
        