結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー krotonkroton
提出日時 2015-01-09 02:08:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 591 bytes
コンパイル時間 1,343 ms
コンパイル使用メモリ 155,664 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 22:52:42
合計ジャッジ時間 1,967 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int N, A[111];
int solve(){
	map<int, int> mp;
	for(int i=0;i<N;i++)
		mp[A[i]]++;

	priority_queue<int> Q;
	for(const auto &ps : mp)
		Q.push(ps.second);

	int res = 0;
	while(Q.size() >= 3){
		int a = Q.top(); Q.pop();
		int b = Q.top(); Q.pop();
		int c = Q.top(); Q.pop();

		++res;
		if(a > 1)Q.push(a - 1);
		if(b > 1)Q.push(b - 1);
		if(c > 1)Q.push(c - 1);
	}

	return res;
}

int main(){
	int T; cin >> T;
	while(T--){
		cin >> N;
		for(int i=0;i<N;i++)
			cin >> A[i];

		cout << solve() << endl;
	}
	return 0;
}
0