結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | rpy3cpp |
提出日時 | 2015-07-13 15:19:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 64 ms / 5,000 ms |
コード長 | 462 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 10,972 KB |
実行使用メモリ | 8,760 KB |
最終ジャッジ日時 | 2023-09-22 15:22:37 |
合計ジャッジ時間 | 1,065 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
8,712 KB |
testcase_01 | AC | 63 ms
8,596 KB |
testcase_02 | AC | 46 ms
8,760 KB |
testcase_03 | AC | 64 ms
8,692 KB |
ソースコード
import heapq import collections def solve(N, Ls): counts = collections.Counter(Ls) vals = [-c for c in counts.values()] heapq.heapify(vals) while N: c = -vals[0] if c <= N // 3: return N // 3 newc = (N - c) // 2 N -= c - newc heapq.heapreplace(vals, -newc) return 0 T = int(input()) for t in range(T): N = int(input()) Ls = list(map(int, input().split())) print(solve(N, Ls))