結果
問題 |
No.120 傾向と対策:門松列(その1)
|
ユーザー |
![]() |
提出日時 | 2025-10-14 21:34:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 223 ms / 5,000 ms |
コード長 | 760 bytes |
コンパイル時間 | 459 ms |
コンパイル使用メモリ | 82,724 KB |
実行使用メモリ | 79,444 KB |
最終ジャッジ日時 | 2025-10-14 21:34:53 |
合計ジャッジ時間 | 2,527 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
from collections import defaultdict from heapq import heappop, heappush T = int(input()) ansl = [] for i in range(T): N = int(input()) L = list(map(int, input().split())) d = defaultdict(int) for l in L: d[l] += 1 cnt = [] for k, v in d.items(): heappush(cnt, -v) # 3つ取る ans = 0 if len(cnt) < 3: ansl.append(0) continue while len(cnt) >= 3: memo = [] for i in range(3): num = heappop(cnt) num += 1 if num != 0: memo.append(num) # 3回まわしてから、pushする for num in memo: heappush(cnt, num) else: ans += 1 ansl.append(ans) print(*ansl, sep='\n')