結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー mkawa2mkawa2
提出日時 2020-01-03 09:53:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,017 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,888 KB
最終ジャッジ日時 2023-08-14 19:06:13
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
8,888 KB
testcase_01 AC 81 ms
8,736 KB
testcase_02 AC 51 ms
8,720 KB
testcase_03 AC 80 ms
8,768 KB
権限があれば一括ダウンロードができます

ソースコード

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=[-x for x in ll.values()]
        heapify(ll)
        ans=0
        while len(ll)>2:
            l1=-heappop(ll)
            l2=-heappop(ll)
            l3=-heappop(ll)
            #print(l1,l2,l3,ll)
            l1-=1
            l2-=1
            l3-=1
            ans+=1
            if l1:heappush(ll,-l1)
            if l2:heappush(ll,-l2)
            if l3:heappush(ll,-l3)
        print(ans)

main()
0