結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー mkawa2mkawa2
提出日時 2019-12-24 15:07:02
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 10,212 KB
最終ジャッジ日時 2023-10-22 00:24:57
合計ジャッジ時間 1,698 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    t=II()
    for _ in range(t):
        n=II()
        ll=LI()
        ll=Counter(ll)
        ll=list(ll.values())
        ll=[-x for x in ll]
        heapify(ll)
        ans=0
        while len(ll)>2:
            l1=-heappop(ll)
            l2=-heappop(ll)
            l3=-heappop(ll)
            ans+=l3
            heappush(ll,-l1+l3)
            heappush(ll,-l2+l3)
        print(ans)

main()
0