結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー 👑 KazunKazun
提出日時 2021-05-21 01:29:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 457 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 78,096 KB
最終ジャッジ日時 2024-04-18 14:12:52
合計ジャッジ時間 1,469 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify
from collections import defaultdict

T=int(input())

for _ in range(T):
    N=int(input())
    L=list(map(int,input().split()))

    D=defaultdict(int)
    for a in L:
        D[a]+=1

    Q=list(D.keys())
    heapify(Q)

    X=0
    while len(Q)>=3:
        p=Q.pop()
        q=Q.pop()
        r=Q.pop()

        X+=1

        for x in [p,q,r]:
            D[x]-=1
            if D[x]>=1:
                Q.append(x)

    print(X)
0