結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー nnasennnasen
提出日時 2018-01-08 21:16:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 859 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 178,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 00:46:14
合計ジャッジ時間 2,722 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 100000000
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;


int main() {
	int t;
	cin >> t;
	vector<LL> ans;
	while (t--) {
		int n;
		cin >> n;
		map<int, int> mp;
		REP(i, n) {
			int l;
			cin >> l;
			mp[l]++;
		}
		VI v;
		int res = 0;
		for(auto e : mp) {
			v.push_back(e.second);
		}
		while (1) {
			sort(ALL(v));
			reverse(ALL(v));
			if (v.size() >= 3 && v[0] > 0 && v[1] > 0 && v[2] > 0) {
				v[0]--; v[1]--; v[2]--;
				res++;
			}
			else {
				break;
			}
		}
		ans.push_back(res);
	}
	for (int e : ans) cout << e << endl;
	return 0;
}
0