結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー nanaenanae
提出日時 2017-02-10 01:48:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 102 ms / 5,000 ms
コード長 900 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 8,784 KB
最終ジャッジ日時 2023-08-26 23:06:18
合計ジャッジ時間 1,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
8,756 KB
testcase_01 AC 102 ms
8,640 KB
testcase_02 AC 62 ms
8,720 KB
testcase_03 AC 99 ms
8,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import Counter
from heapq import heapify, heappush, heappop

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    T = int(input())

    for i in range(T):
        N = int(input())
        Ls = [int(i) for i in input().split()]
        cnt = Counter(Ls)
        hpq = [-i for i in cnt.values()]
        heapify(hpq)
        ans = 0

        # debug(hpq, locals())

        while len(hpq) >= 3:
            # debug(hpq, locals())
            ans += 1

            tmp = []
            for j in range(3):
                tmp.append(hpq[0] + 1)
                heappop(hpq)

            for j in range(3):
                if tmp[j] < 0:
                    heappush(hpq, tmp[j])

        print(ans)

if __name__ == '__main__':
    solve()
0