結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー maspy
提出日時 2020-02-02 14:11:52
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 786 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2024-09-18 20:44:27
合計ジャッジ時間 1,443 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

T = int(readline())

def get_test_case():
    N = int(readline())
    *L, = map(int,readline().split())
    return N,L

def solve_test_case(N,L):
    A = list(Counter(L).values())
    A = [-x for x in A]
    heapify(A)
    # 多いのを3つ作る、を繰り返す
    n = 0
    while len(A) >= 3:
        n += 1
        a,b,c = [heappop(A) for _ in range(3)]
        a += 1
        b += 1
        c += 1
        for x in [a,b,c]:
            if x < 0:
                heappush(A,x)
    return n

cases = [get_test_case() for _ in range(T)]
for N,L in cases:
    print(solve_test_case(N,L))
0