結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー HAHAHAHAHAHA
提出日時 2016-09-20 10:48:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 625 bytes
コンパイル時間 2,872 ms
コンパイル使用メモリ 156,560 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 23:27:04
合計ジャッジ時間 2,591 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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