結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-12-06 10:28:24 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 606 ms / 5,000 ms | 
| コード長 | 711 bytes | 
| コンパイル時間 | 312 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 82,060 KB | 
| 最終ジャッジ日時 | 2024-12-06 10:28:29 | 
| 合計ジャッジ時間 | 3,909 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
import heapq
T = int(input())
for _ in range(T):
    N = int(input())
    L = sorted(list(map(int,input().split())))
    C = {}
    for i in range(N):
        C[L[i]] = C.get(L[i],0)+1
    C = list(C.items())
    C = sorted([(-c,l) for l,c in C])
    que = []
    for c,x in C:
        heapq.heappush(que,(c,x))
    ans = 0
    while len(que)>=3:
        c1,x1 = heapq.heappop(que)
        c2,x2 = heapq.heappop(que)
        c3,x3 = heapq.heappop(que)
        ans += 1
        c1 += 1
        c2 += 1
        c3 += 1
        if c1<0:
            heapq.heappush(que,(c1,x1))
        if c2<0:
            heapq.heappush(que,(c2,x2))
        if c3<0:
            heapq.heappush(que,(c3,x3))
    print(ans)
        
            
            
            
        