結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー nbisconbisco
提出日時 2017-01-21 23:36:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,796 KB
実行使用メモリ 8,788 KB
最終ジャッジ日時 2023-08-24 19:53:19
合計ジャッジ時間 1,047 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
8,660 KB
testcase_01 AC 85 ms
8,788 KB
testcase_02 AC 54 ms
8,696 KB
testcase_03 AC 84 ms
8,660 KB
権限があれば一括ダウンロードができます

ソースコード

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