結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー mkawa2mkawa2
提出日時 2019-12-24 15:10:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 11,876 KB
実行使用メモリ 10,284 KB
最終ジャッジ日時 2023-10-22 00:31:55
合計ジャッジ時間 1,102 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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)
            l1-=l3
            l2-=l3
            ans+=l3
            if l1:heappush(ll,-l1)
            if l2:heappush(ll,-l2)
        print(ans)

main()
0