結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-29 01:57:16
言語 Python2
(2.7.18)
結果
AC  
実行時間 268 ms / 5,000 ms
コード長 516 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 6,624 KB
最終ジャッジ日時 2023-09-16 23:57:55
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
6,448 KB
testcase_01 AC 268 ms
6,420 KB
testcase_02 AC 132 ms
6,416 KB
testcase_03 AC 254 ms
6,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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