結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー あかりきあかりき
提出日時 2021-02-13 14:40:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 416 ms / 5,000 ms
コード長 565 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 84,996 KB
最終ジャッジ日時 2023-09-27 23:07:33
合計ジャッジ時間 3,186 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 416 ms
84,996 KB
testcase_01 AC 383 ms
82,504 KB
testcase_02 AC 337 ms
81,784 KB
testcase_03 AC 317 ms
82,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import collections
t=int(input())
for i in range(t):
  n=int(input())
  l=list(map(int,input().split()))
  l=collections.Counter(l)
  l=list(l.values())
  if len(l)<3:
    print(0)
  else:
    for i in range(len(l)):
      l[i]*=-1
    heapq.heapify(l)
    ans=0
    for i in range(n//3+1):
      a=heapq.heappop(l)
      b=heapq.heappop(l)
      c=heapq.heappop(l)
      if a<0 and b<0 and c<0:
        a+=1;b+=1;c+=1
        ans+=1
      else:
        break
      heapq.heappush(l,a)
      heapq.heappush(l,b)
      heapq.heappush(l,c)
    print(ans)
0