結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー |
![]() |
提出日時 | 2025-03-20 19:01:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 131 ms / 5,000 ms |
コード長 | 1,093 bytes |
コンパイル時間 | 350 ms |
コンパイル使用メモリ | 81,844 KB |
実行使用メモリ | 91,376 KB |
最終ジャッジ日時 | 2025-03-20 19:02:35 |
合計ジャッジ時間 | 1,434 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
import bisect from collections import Counter def max_kadomatsu_groups(test_cases): results = [] for case in test_cases: N, L = case if N < 3: results.append(0) continue freq = list(Counter(L).values()) max_possible = N // 3 low, high = 0, max_possible best = 0 while low <= high: mid = (low + high) // 2 total = sum(min(f, mid) for f in freq) if total >= 3 * mid: best = mid low = mid + 1 else: high = mid - 1 results.append(best) return results # Read input and process import sys def main(): input = sys.stdin.read().split() ptr = 0 T = int(input[ptr]) ptr += 1 test_cases = [] for _ in range(T): N = int(input[ptr]) ptr += 1 L = list(map(int, input[ptr:ptr + N])) ptr += N test_cases.append((N, L)) results = max_kadomatsu_groups(test_cases) for res in results: print(res) if __name__ == '__main__': main()