結果
問題 |
No.120 傾向と対策:門松列(その1)
|
ユーザー |
|
提出日時 | 2023-06-29 00:16:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 359 ms / 5,000 ms |
コード長 | 541 bytes |
コンパイル時間 | 627 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 80,868 KB |
最終ジャッジ日時 | 2024-07-05 17:34:53 |
合計ジャッジ時間 | 2,683 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
from collections import Counter from heapq import heapify, heappop, heappush for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) counter = Counter(A) H = [-cnt for cnt in counter.values()] heapify(H) ans = 0 while len(H) >= 3: a = -heappop(H) b = -heappop(H) c = -heappop(H) ans += 1 if a > 1: heappush(H, -a + 1) if b > 1: heappush(H, -b + 1) if c > 1: heappush(H, -c + 1) print(ans)