結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー nenuonnenuon
提出日時 2017-07-17 00:52:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 666 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 178,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-29 17:11:31
合計ジャッジ時間 2,345 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define p(s) cout<<(s)<<endl
typedef long long ll;
using namespace std;

int main(){
	int T;
	cin >> T;
	REP(i,0,T){
		int N;
		cin >> N;
		vector<int> L(N);
		ll sum = 0;
		map<int, int> m;
		REP(i,0,N){
			cin >> L[i];
			sum += L[i];
			m[L[i]]++;
		}

		priority_queue<int> pq;

		for (auto i : m){
			pq.push(i.second);
		}
		int ans = 0;
		if (m.size() >= 3){
			while (1){
				int a = pq.top(); pq.pop();
				int b = pq.top(); pq.pop();
				int c = pq.top(); pq.pop();
				if (c <= 0)	break;
				ans++;
				pq.push(a - 1);
				pq.push(b - 1);
				pq.push(c - 1);
			}
		}
		p(ans);
	}
}
0