結果
問題 |
No.120 傾向と対策:門松列(その1)
|
ユーザー |
![]() |
提出日時 | 2022-02-14 00:01:20 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 133 ms / 5,000 ms |
コード長 | 563 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-06-29 05:52:03 |
合計ジャッジ時間 | 1,323 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
from collections import Counter import heapq t=int(input()) for tests in range(t): N=int(input()) A=list(map(int,input().split())) C=Counter(A) H=list(C.values()) H=[-h for h in H] heapq.heapify(H) ANS=0 while len(H)>=3: x=heapq.heappop(H) y=heapq.heappop(H) z=heapq.heappop(H) x+=1 y+=1 z+=1 ANS+=1 if x!=0: heapq.heappush(H,x) if y!=0: heapq.heappush(H,y) if z!=0: heapq.heappush(H,z) print(ANS)