結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー HIROPON87069639HIROPON87069639
提出日時 2016-02-14 23:39:51
言語 Python2
(2.7.18)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 874 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 7,092 KB
実行使用メモリ 6,760 KB
最終ジャッジ日時 2023-10-22 05:24:46
合計ジャッジ時間 939 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
6,632 KB
testcase_01 AC 88 ms
6,616 KB
testcase_02 AC 54 ms
6,760 KB
testcase_03 AC 88 ms
6,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
def calc(Alist, M):
    Alist.sort()
    Alist.append(0)
    max1 = 0
    max2 = 0
    cnt = 1
    ccc = 1
    for i in range(1, M+1):
        if Alist[i] == Alist[i-1]:
            cnt += 1
        elif Alist[i] != Alist[i-1]:
            ccc += 1
            if max1 <= cnt:
                max2 = max1
                max1 = cnt
            if max2 < cnt < max1:
                max2 = cnt
            cnt = 1
    m3 = M // 3
    if max1 <= m3:
        ans = m3
    else:
        N = M - max1
        n2 = N // 2
        if max2 <= n2:
            ans = n2
        elif n2 < max2:
            ans = M - max1 - max2
    if ccc <= 3:
        ans = 0
    return ans


Alist = []
out = []
L = input()
for i in range(0, L):
    M = input()
    Alist = map(int, raw_input().split())
    out.append(calc(Alist, M))
for i in range(0, L):
    print out[i]
0