結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー ああいいああいい
提出日時 2022-05-22 20:07:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 564 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 76,856 KB
最終ジャッジ日時 2023-10-20 17:16:55
合計ジャッジ時間 1,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
76,856 KB
testcase_01 AC 142 ms
76,744 KB
testcase_02 AC 130 ms
76,780 KB
testcase_03 AC 136 ms
76,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
from collections import defaultdict

def f(d,mid):
    tmp = 0
    for i in d:
        v = d[i]
        tmp += min(mid,v)
    return tmp >= 3 * mid
def calc(l):
    N = len(l)
    if N <= 2:
        return 0
    d = defaultdict(int)
    for i in l:
        d[i] += 1
    start = 0
    end = N
    while end - start > 1:
        mid = end + start >> 1
        if f(d,mid):
            start = mid
        else:
            end = mid
    return start
for _ in range(T):
    N = int(input())
    l = list(map(int,input().split()))
    print(calc(l))
0