結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー maspymaspy
提出日時 2020-02-02 14:11:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 786 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 11,876 KB
実行使用メモリ 14,252 KB
最終ジャッジ日時 2023-10-19 00:49:36
合計ジャッジ時間 1,509 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
14,252 KB
testcase_01 AC 122 ms
14,224 KB
testcase_02 AC 75 ms
12,364 KB
testcase_03 AC 123 ms
14,132 KB
権限があれば一括ダウンロードができます

ソースコード

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