結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー furafura
提出日時 2020-04-20 11:25:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 592 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 201,240 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 00:33:39
合計ジャッジ時間 2,768 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
5,248 KB
testcase_01 AC 23 ms
5,376 KB
testcase_02 AC 12 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

void solve(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<int> X=a;
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());

	vector<int> hist(n);
	rep(i,n) hist[lower_bound(X.begin(),X.end(),a[i])-X.begin()]++;

	int lo=0,hi=n;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		int cnt=0;
		rep(x,n) cnt+=min(hist[x],mi);
		if(cnt>=3*mi) lo=mi;
		else          hi=mi;
	}
	printf("%d\n",lo);
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0