結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー titiatitia
提出日時 2022-02-14 00:01:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 563 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 8,720 KB
最終ジャッジ日時 2023-09-11 15:45:40
合計ジャッジ時間 1,382 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
8,652 KB
testcase_01 AC 107 ms
8,612 KB
testcase_02 AC 68 ms
8,720 KB
testcase_03 AC 107 ms
8,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import heapq

t=int(input())
for tests in range(t):
    N=int(input())
    A=list(map(int,input().split()))

    C=Counter(A)
    H=list(C.values())

    H=[-h for h in H]
    heapq.heapify(H)

    ANS=0

    while len(H)>=3:
        x=heapq.heappop(H)
        y=heapq.heappop(H)
        z=heapq.heappop(H)

        x+=1
        y+=1
        z+=1
        ANS+=1

        if x!=0:
            heapq.heappush(H,x)
        if y!=0:
            heapq.heappush(H,y)
        if z!=0:
            heapq.heappush(H,z)
    print(ANS)

    
0