結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | しらっ亭 |
提出日時 | 2015-07-01 02:33:28 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 96 ms / 5,000 ms |
コード長 | 762 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 10,788 KB |
実行使用メモリ | 8,756 KB |
最終ジャッジ日時 | 2023-09-22 04:53:14 |
合計ジャッジ時間 | 1,152 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
8,756 KB |
testcase_01 | AC | 96 ms
8,632 KB |
testcase_02 | AC | 64 ms
8,600 KB |
testcase_03 | AC | 93 ms
8,748 KB |
ソースコード
from collections import Counter import heapq def solve(N, L): c2 = Counter(Counter(L).values()) h = [] for n in sorted(c2.keys(), reverse=True): k = c2[n] for i in range(k): heapq.heappush(h, -n) c = 0 while len(h) >= 3: c += 1 n1 = heapq.heappop(h) n2 = heapq.heappop(h) n3 = heapq.heappop(h) if n1 < -1: heapq.heappush(h, n1 + 1) if n2 < -1: heapq.heappush(h, n2 + 1) if n3 < -1: heapq.heappush(h, n3 + 1) return c def main(): T = int(input()) for t in range(T): N = int(input()) L = list(map(int, input().split())) print(solve(N, L)) if __name__ == '__main__': main()