結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー masamasa
提出日時 2015-05-11 16:51:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 980 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 82,808 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 02:39:52
合計ジャッジ時間 1,675 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <queue>

using namespace std;

int main() {
	int t, n, l;

	cin >> t;
	vector<int> ans(t, 0);
	for (int i = 0; i < t; i++) {
		cin >> n;
		map<int, int> banboo;
		for (int j = 0; j < n; j++) {
			cin >> l;
			if (banboo.count(l) > 0) {
				banboo[l]++;
			} else {
				banboo[l] = 1;
			}
		}

		priority_queue< pair<int , int> > que;
		for (auto it = banboo.begin(); it != banboo.end(); it++) {
			que.push(make_pair((*it).second, (*it).first));
		}

		while (que.size() >= 3) {
			ans[i]++;
			auto q1 = que.top(); que.pop();
			auto q2 = que.top(); que.pop();
			auto q3 = que.top(); que.pop();

			q1.first--;
			q2.first--;
			q3.first--;
			if (q1.first > 0) { que.push(q1); }
			if (q2.first > 0) { que.push(q3); }
			if (q3.first > 0) { que.push(q3); }
		}
	}

	for (int i = 0; i < t; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}
0