結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | kutsutama |
提出日時 | 2019-01-14 04:17:04 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 135 ms / 5,000 ms |
コード長 | 782 bytes |
コンパイル時間 | 121 ms |
コンパイル使用メモリ | 10,940 KB |
実行使用メモリ | 8,756 KB |
最終ジャッジ日時 | 2023-08-28 19:08:30 |
合計ジャッジ時間 | 1,259 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
8,720 KB |
testcase_01 | AC | 132 ms
8,696 KB |
testcase_02 | AC | 77 ms
8,756 KB |
testcase_03 | AC | 130 ms
8,712 KB |
ソースコード
import collections import heapq def solve(N, L): c = collections.Counter() for Li in L: c[Li] -= 1 if len(c) < 3: return 0 res = 0 cnt = list(c.values()) heapq.heapify(cnt) mx = [0] * 3 while True: kadomatsu = True for i in range(len(mx)): mx[i] = heapq.heappop(cnt) if mx[i] >= 0: kadomatsu = False if kadomatsu: res += 1 else: break for i in range(len(mx)): heapq.heappush(cnt, mx[i] + 1) return res T = int(input()) lis = [0] * T for tt in range(T): nt = int(input()) lt = [int(x) for x in input().split()] lis[tt] = solve(nt, lt) print(*lis, sep='\n')