結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー FromBooskaFromBooska
提出日時 2023-05-19 16:56:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 624 ms / 5,000 ms
コード長 612 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 86,796 KB
実行使用メモリ 87,584 KB
最終ジャッジ日時 2023-08-22 21:30:38
合計ジャッジ時間 3,786 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 581 ms
85,192 KB
testcase_01 AC 624 ms
87,584 KB
testcase_02 AC 451 ms
82,032 KB
testcase_03 AC 573 ms
84,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from heapq import *

T = int(input())
for t in range(T):
    N = int(input())
    L = list(map(int, input().split()))
    H = []
    heapify(H)
    counted = Counter(L)
    for n in counted:
        heappush(H, (-counted[n], n))

    count = 0
    while len(H) >= 3:
        count += 1
        c1, n1 = heappop(H)
        c2, n2 = heappop(H)
        c3, n3 = heappop(H)
        if c1 < -1:
            heappush(H, (c1+1, n1))
        if c2 < -1:
            heappush(H, (c2+1, n2))    
        if c3 < -1:
            heappush(H, (c3+1, n3))    
        #print(H)
    print(count)
0