結果

問題 No.120 傾向と対策:門松列(その1)
コンテスト
ユーザー yaoshimax
提出日時 2015-03-29 01:57:16
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 352 ms / 5,000 ms
コード長 516 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 126 ms
コンパイル使用メモリ 77,496 KB
最終ジャッジ日時 2025-12-03 14:31:00
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import heappop,heappush
import collections
T=int(raw_input())
for ti in range(T):
    N=int(raw_input())
    L=map(int,raw_input().split())
    LDict=collections.Counter(L)
    hp=[]
    for v,n in LDict.items():
        heappush(hp,-n)
    ans=0
    while len(hp)>=3:
        a=heappop(hp)
        b=heappop(hp)
        c=heappop(hp)
        ans+=1
        if a+1<0:
            heappush(hp,a+1)
        if b+1<0:
            heappush(hp,b+1)
        if c+1<0:
            heappush(hp,c+1)
    print ans
0