結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-24 11:00:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 570 ms / 5,000 ms
コード長 642 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 83,768 KB
最終ジャッジ日時 2024-04-26 14:53:05
合計ジャッジ時間 3,476 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 570 ms
83,768 KB
testcase_01 AC 522 ms
82,040 KB
testcase_02 AC 398 ms
81,532 KB
testcase_03 AC 478 ms
81,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())
from collections import Counter
import heapq
for _ in range(t):
    n = int(input())
    L = list(map(int, input().split()))
    C = Counter(L)
    q = []
    for k, v in C.items():
        q.append((-v, k))
    heapq.heapify(q)
    ans = 0
    while len(q) >= 3:
        v1, k1 = heapq.heappop(q)
        v2, k2 = heapq.heappop(q)
        v3, k3 = heapq.heappop(q)
        v1, v2, v3 = -v1, -v2, -v3
        if v1 > 1:
            heapq.heappush(q, (-(v1-1), k1))
        if v2 > 1:
            heapq.heappush(q, (-(v2-1), k2))
        if v3 > 1:
            heapq.heappush(q, (-(v3-1), k3))
        ans += 1
    print(ans)
0