結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー nbisco
提出日時 2017-01-21 23:36:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 113 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-12-23 05:16:17
合計ジャッジ時間 1,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import heapq

T = int(input())

def kado():
    N = int(input())
    L = collections.Counter(map(int, input().strip().split(" ")))
    Lv = L.values()
    if len(Lv) < 3:
        return 0
    heap = [-i for i in Lv]
    heapq.heapify(heap)

    total = 0
    while True:
        k1 = heapq.heappop(heap)
        k2 = heapq.heappop(heap)
        k3 = heapq.heappop(heap)
        if k3 == 0:
            break
        total += 1
        heapq.heappush(heap, k1+1)
        heapq.heappush(heap, k2+1)
        heapq.heappush(heap, k3+1)
    return total

print("\n".join([str(kado()) for i in range(T)]))
0