結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-07-13 15:19:02 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 80 ms / 5,000 ms | 
| コード長 | 462 bytes | 
| コンパイル時間 | 236 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 10,752 KB | 
| 最終ジャッジ日時 | 2024-07-08 06:58:11 | 
| 合計ジャッジ時間 | 1,060 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
import heapq
import collections
def solve(N, Ls):
    counts = collections.Counter(Ls)
    vals = [-c for c in counts.values()]
    heapq.heapify(vals)
    while N:
        c = -vals[0]
        if c <= N // 3:
            return N // 3
        newc = (N - c) // 2
        N -= c - newc
        heapq.heapreplace(vals, -newc)
    return 0
T = int(input())
for t in range(T):
    N = int(input())
    Ls = list(map(int, input().split()))
    print(solve(N, Ls))
            
            
            
        