結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー fiordfiord
提出日時 2015-07-01 00:29:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 612 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 156,560 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 04:47:32
合計ジャッジ時間 2,120 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
4,380 KB
testcase_01 AC 52 ms
4,380 KB
testcase_02 AC 27 ms
4,380 KB
testcase_03 AC 53 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0