結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  あかりき | 
| 提出日時 | 2021-02-13 14:40:07 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 426 ms / 5,000 ms | 
| コード長 | 565 bytes | 
| コンパイル時間 | 444 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 81,368 KB | 
| 最終ジャッジ日時 | 2024-07-20 17:30:32 | 
| 合計ジャッジ時間 | 3,004 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
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)
            
            
            
        