結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー rlangevin
提出日時 2023-01-16 20:23:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 352 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 81,424 KB
最終ジャッジ日時 2024-12-31 09:31:17
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from heapq import *
T = int(input())
for _ in range(T):
    N = int(input())
    L = list(map(int, input().split()))
    D = defaultdict(int)
    for a in L:
        D[a] += 1
    H = []
    for k, v in D.items():
        heappush(H, -v)
        
    ans = 0
    while len(H) >= 3:
        a = heappop(H)
        b = heappop(H)
        c = heappop(H)
        a, b, c = -a - 1, -b - 1, -c - 1
        ans += 1
        if a:
            heappush(H, -a)
        if b:
            heappush(H, -b)
        if c:
            heappush(H, -c)
    print(ans)    
0