結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー koyumeishikoyumeishi
提出日時 2015-01-09 00:08:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 948 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 89,500 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 22:46:10
合計ジャッジ時間 1,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;


int main(){
	int T;
	cin >> T;
	for(int t=0; t<T; t++){
		int N;
		cin >> N;
		vector<int> L(N);
		for(int i=0; i<N; i++) cin >> L[i];
		map<int, int> m;
		for(int i=0; i<N; i++){
			m[L[i]]++;
		}
		vector< pair<int,int> > v;
		for(auto itr = m.begin(); itr!=m.end(); itr++){
			v.push_back( {itr->second, itr->first} );
		}
		priority_queue< pair<int,int> > pq(v.begin(), v.end());
		int ans = 0;
		while(pq.size() >= 3){
			auto a = pq.top(); pq.pop();
			auto b = pq.top(); pq.pop();
			auto c = pq.top(); pq.pop();
			ans++;
			if(a.first > 1){
				pq.push( {a.first-1, a.second} );
			}
			if(b.first > 1){
				pq.push( {b.first-1, b.second} );
			}
			if(c.first > 1){
				pq.push( {c.first-1, c.second} );
			}
		}
		cout << ans << endl;
	}
	return 0;
}
0