結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー lloyzlloyz
提出日時 2023-06-29 00:16:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 487 ms / 5,000 ms
コード長 541 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 83,556 KB
最終ジャッジ日時 2023-09-19 05:09:09
合計ジャッジ時間 3,481 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 487 ms
83,556 KB
testcase_01 AC 430 ms
82,096 KB
testcase_02 AC 357 ms
83,104 KB
testcase_03 AC 373 ms
81,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

for _ in range(int(input())):
    n = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)
    H = [-cnt for cnt in counter.values()]
    heapify(H)
    ans = 0
    while len(H) >= 3:
        a = -heappop(H)
        b = -heappop(H)
        c = -heappop(H)
        ans += 1
        if a > 1:
            heappush(H, -a + 1)
        if b > 1:
            heappush(H, -b + 1)
        if c > 1:
            heappush(H, -c + 1)
    print(ans)
0