結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー pekempeypekempey
提出日時 2016-12-22 21:18:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 555 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 175,744 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 05:43:58
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		map<int, int> mp;
		for (int i = 0; i < n; i++) {
			int a;
			scanf("%d", &a);
			mp[a]++;
		}
		priority_queue<int> q;
		for (auto kv : mp) {
			q.push(kv.second);
		}
		int ans = 0;
		while (q.size() >= 3) {
			int x = q.top(); q.pop();
			int y = q.top(); q.pop();
			int z = q.top(); q.pop();
			if (x - 1 > 0) q.push(x - 1);
			if (y - 1 > 0) q.push(y - 1);
			if (z - 1 > 0) q.push(z - 1);
			ans++;
		}
		cout << ans << endl;
	}
}
0