結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー 👑 KazunKazun
提出日時 2021-05-21 01:55:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 242 ms / 5,000 ms
コード長 512 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 78,960 KB
最終ジャッジ日時 2024-04-18 14:12:57
合計ジャッジ時間 1,812 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 242 ms
77,880 KB
testcase_01 AC 221 ms
78,548 KB
testcase_02 AC 229 ms
78,960 KB
testcase_03 AC 222 ms
78,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify,heappop,heappush
from collections import defaultdict

T=int(input())
Ans=[]

for _ in range(T):
    N=int(input())
    L=list(map(int,input().split()))

    D=defaultdict(int)
    for a in L:
        D[a]+=1

    Q=[-k for k in D.values()]
    heapify(Q)

    X=0
    while len(Q)>=3:
        p=-heappop(Q)
        q=-heappop(Q)
        r=-heappop(Q)

        X+=1
        for x in [p,q,r]:
            if x>1:
                heappush(Q,-(x-1))

    Ans.append(X)

print(*Ans,sep="\n")
0