結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー tkzw_21tkzw_21
提出日時 2015-01-08 23:59:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 792 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 155,988 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 22:45:50
合計ジャッジ時間 2,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define INF INT_MAX / 2
#define MOD 1000000007

using namespace std;

typedef pair<int,int> PII;
typedef long long ll;

int main(void) {
	int t;
	cin >> t;
	for(int ii=0;ii<t;ii++){
		int n;
		cin >> n;
		vector<int> l(n),cnt(n);
		map<int,int> count;

		for(int i=0;i<n;i++){
			cin >> l[i];
			count[l[i]]++;
		}

		auto it = count.begin();int m=0;
		for(;it!=count.end();it++)
			cnt[m++] = it->second;

		sort(cnt.begin(),cnt.end(),greater<int>());
		int ans = 0;

		while(cnt[0] != 0){
			int kadomatuCount = 0;
			for(int i=0;i<n;i++){
				if(cnt[i]>0){
					kadomatuCount++;
					cnt[i]--;
				}
				if(kadomatuCount==3){
					kadomatuCount = 0;
					ans++;
					break;
				}
			}
			sort(cnt.begin(),cnt.end(),greater<int>());
		}

		cout << ans << endl;
	}
}
0