結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  fiord | 
| 提出日時 | 2015-07-01 00:29:46 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 48 ms / 5,000 ms | 
| コード長 | 612 bytes | 
| コンパイル時間 | 1,249 ms | 
| コンパイル使用メモリ | 170,740 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-07 21:32:00 | 
| 合計ジャッジ時間 | 1,861 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
	int t;	cin>>t;
	while(t--){
		int n;	cin>>n;
		vector<int> l(n);
		map<int,int> data;
		for(int i=0;i<n;i++){
			cin>>l[i];
			data[l[i]]++;
		}
		priority_queue<int> pq;
		for(map<int,int>::iterator i=data.begin();i!=data.end();i++){
			pq.push(i->second);
		}
		if(pq.size()<3){
			cout<<0<<endl;
			continue;
		}
		int ans=0;
		while(1){
			int a=pq.top();	pq.pop();
			int b=pq.top(); pq.pop();
			int c=pq.top(); pq.pop();
			if(c<=0){
				cout<<ans<<endl;
				break;
			}
			ans++;
			pq.push(a-1);	pq.push(b-1);	pq.push(c-1);
		}
	}
	return 0;
}
            
            
            
        