結果
| 問題 | No.120 傾向と対策:門松列(その1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-30 17:37:26 |
| 言語 | PyPy2 (7.3.20) |
| 結果 |
AC
|
| 実行時間 | 475 ms / 5,000 ms |
| コード長 | 487 bytes |
| 記録 | |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 81,024 KB |
| 実行使用メモリ | 86,988 KB |
| 最終ジャッジ日時 | 2026-05-19 05:05:34 |
| 合計ジャッジ時間 | 3,722 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
from collections import Counter
import heapq
def solve():
N = int(raw_input())
L = map(int, raw_input().split())
L = [-v for v in Counter(L).values()]
heapq.heapify(L)
ans = 0
while len(L) >= 3:
a, b, c = heapq.heappop(L), heapq.heappop(L), heapq.heappop(L)
ans += 1
if a < -1: heapq.heappush(L, a+1)
if b < -1: heapq.heappush(L, b+1)
if c < -1: heapq.heappush(L, c+1)
print ans
for _ in xrange(input()):
solve()