結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-08 00:55:38
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 651 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 156,192 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-17 16:01:40
合計ジャッジ時間 2,582 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void calc() {
	int N;
	cin >> N;
	vector<int> L(N);
	long long sum = 0;
	map<int, int> m;
	for (int i = 0; i < N; i++)
	{
		cin >> L[i];
		sum += L[i];
		m[L[i]]++;
	}
	if (N < 3){
		cout << 0 << endl;
		return;
	}
	
	priority_queue<int> pq;
	for (auto i : m){
		pq.push(i.second);
	}
	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;
	for (int i = 0; i < T; i++)
	{
		calc();
	}
}
0