結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー evawenisevawenis
提出日時 2020-08-18 15:17:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 494 bytes
コンパイル時間 2,818 ms
コンパイル使用メモリ 203,936 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 07:35:58
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
5,248 KB
testcase_01 AC 21 ms
5,376 KB
testcase_02 AC 12 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int t; cin>>t;
	for(int i=0;i<t;++i){
		int n; cin>>n;
		unordered_map<int,int>m;
		for(int j=0;j<n;++j){
			int l; cin>>l;
			++m[l];
		}
		priority_queue<int>q;
		for(auto&&j:m)q.push({j.second});
		int ans=0;
		while(q.size()>2){
			vector<int>abc(3);
			for(auto&&j:abc){
				j=q.top(); q.pop();
			}
			++ans;
			for(auto&&j:abc){
				if(j>1)q.push(j-1);
			}
		}
		cout<<ans<<"\n"s;
	}
}
0