結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-08 00:57:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 661 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 156,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 16:01:47
合計ジャッジ時間 2,149 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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]]++;
	}
	
	priority_queue<int> pq;

	for (auto i : m){
		pq.push(i.second);
	}

	if (m.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;
	for (int i = 0; i < T; i++)
	{
		calc();
	}
}
0