結果
問題 |
No.120 傾向と対策:門松列(その1)
|
ユーザー |
![]() |
提出日時 | 2020-01-03 09:53:11 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 102 ms / 5,000 ms |
コード長 | 1,017 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-11-22 18:55:53 |
合計ジャッジ時間 | 973 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def main(): t=II() for _ in range(t): n=II() ll=LI() ll=Counter(ll) ll=[-x for x in ll.values()] heapify(ll) ans=0 while len(ll)>2: l1=-heappop(ll) l2=-heappop(ll) l3=-heappop(ll) #print(l1,l2,l3,ll) l1-=1 l2-=1 l3-=1 ans+=1 if l1:heappush(ll,-l1) if l2:heappush(ll,-l2) if l3:heappush(ll,-l3) print(ans) main()