結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー convexineqconvexineq
提出日時 2020-12-16 09:57:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 420 ms / 5,000 ms
コード長 466 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 80,920 KB
最終ジャッジ日時 2023-10-20 09:02:50
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 420 ms
80,920 KB
testcase_01 AC 374 ms
79,760 KB
testcase_02 AC 294 ms
79,540 KB
testcase_03 AC 297 ms
78,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
from collections import Counter
from heapq import *
for _ in range(T):
    n = int(input())
    a = map(int,input().split())
    d = Counter(a)
    *s, = sorted(-v for k,v in d.items())
    
    ans = 0
    heapify(s)
    while len(s) >= 3:
        ans += 1
        x = heappop(s)
        y = heappop(s)
        z = heappop(s)
        if x <= -2: heappush(s,x+1)
        if y <= -2: heappush(s,y+1)
        if z <= -2: heappush(s,z+1)
    print(ans)
0