結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-01-09 02:08:30 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 55 ms / 5,000 ms | 
| コード長 | 591 bytes | 
| コンパイル時間 | 1,800 ms | 
| コンパイル使用メモリ | 170,448 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-13 03:30:29 | 
| 合計ジャッジ時間 | 2,302 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, A[111];
int solve(){
	map<int, int> mp;
	for(int i=0;i<N;i++)
		mp[A[i]]++;
	priority_queue<int> Q;
	for(const auto &ps : mp)
		Q.push(ps.second);
	int res = 0;
	while(Q.size() >= 3){
		int a = Q.top(); Q.pop();
		int b = Q.top(); Q.pop();
		int c = Q.top(); Q.pop();
		++res;
		if(a > 1)Q.push(a - 1);
		if(b > 1)Q.push(b - 1);
		if(c > 1)Q.push(c - 1);
	}
	return res;
}
int main(){
	int T; cin >> T;
	while(T--){
		cin >> N;
		for(int i=0;i<N;i++)
			cin >> A[i];
		cout << solve() << endl;
	}
	return 0;
}
            
            
            
        