結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー tnodinotnodino
提出日時 2022-06-22 19:11:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 588 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-23 22:59:32
合計ジャッジ時間 1,507 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
10,880 KB
testcase_01 AC 139 ms
10,880 KB
testcase_02 AC 89 ms
10,880 KB
testcase_03 AC 138 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heappop,heappush
def solve():
    N = int(input())
    L = list(map(int,input().split()))
    dic = defaultdict(int)
    for i in range(N):
        dic[L[i]] += 1
    hq = []
    for v in dic.values():
        heappush(hq, -v)
    ans = 0
    while len(hq) >= 3:
        ans += 1
        v = []
        for _ in range(3):
            v.append(heappop(hq))
        for i in range(3):
            if v[i] + 1 == 0:
                continue
            heappush(hq, v[i]+1)
    print(ans)

T = int(input())
for _ in range(T):
    solve()
0