結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  HAHAHA | 
| 提出日時 | 2016-09-20 10:48:16 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 56 ms / 5,000 ms | 
| コード長 | 625 bytes | 
| コンパイル時間 | 1,775 ms | 
| コンパイル使用メモリ | 172,496 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-17 10:07:38 | 
| 合計ジャッジ時間 | 2,880 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
void F(){
	int n;
	cin >> n;
	vector<int> v(n);
	long long sum=0;
	map<int, int> mp;
	
	for(int i=0;i<n;i++){
		cin >> v[i];
		sum+=v[i];
		mp[v[i]]++;
	}
	
	priority_queue<int> pq;
	
	for(auto i : mp){
		pq.push(i.second);
	}
	
	if(mp.size() < 3){
		cout << 0 << endl;
		return;
	}
	
	int ans=0;
	while(true){
		int a=pq.top(); pq.pop();
		int b=pq.top(); pq.pop();
		int c=pq.top(); pq.pop();
		
		if(c<=0){
			cout << ans << endl;
			return;
		}
		ans++;
		pq.push(a-1);
		pq.push(b-1);
		pq.push(c-1);
	}
}
int main(){
	int t;
	cin >> t;
	while(t--){
		F();
	}
	return 0;
}
            
            
            
        