結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  FromBooska | 
| 提出日時 | 2023-04-08 06:59:24 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 440 ms / 5,000 ms | 
| コード長 | 1,082 bytes | 
| コンパイル時間 | 257 ms | 
| コンパイル使用メモリ | 82,792 KB | 
| 実行使用メモリ | 82,216 KB | 
| 最終ジャッジ日時 | 2024-10-03 03:56:30 | 
| 合計ジャッジ時間 | 2,726 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
# 同じ長さでない3本を選べばいい
# 長さごとに本数を数えて、本数降順として使うか
# それで間に合うか? N<100なので間に合うかも
# すべてWA出た、本数降順から取るアルゴリズムが間違っている
# できるだけ平均的に取る必要ある
# 最後が長さAが2本、長さBが2本、長さC以後が0本となったらアウトだ
T = int(input())
for t in range(T):
    N = int(input())
    L = list(map(int, input().split()))
    from collections import Counter
    counted = Counter(L)
    #print(counted)
    #print(type(counted))
    C = []
    for n, c in counted.items():
        C.append([-c, n])
    from heapq import *
    heapify(C)
    #print(C)
    count = 0
    while len(C) >= 3:
        count += 1
        c1, n1 = heappop(C)
        c2, n2 = heappop(C)
        c3, n3 = heappop(C)
        if c1+1 < 0:
            heappush(C, [c1+1, n1])
        if c2+1 < 0:
            heappush(C, [c2+1, n2])
        if c3+1 < 0:
            heappush(C, [c3+1, n3])
        #print(C)
    print(count)
            
            
            
        