結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-20 11:25:12 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 5,000 ms | 
| コード長 | 592 bytes | 
| コンパイル時間 | 2,281 ms | 
| コンパイル使用メモリ | 198,692 KB | 
| 最終ジャッジ日時 | 2025-01-09 21:52:55 | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:8:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~
main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         rep(i,n) scanf("%d",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:31:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         int q; scanf("%d",&q); rep(_,q) solve();
      |                ~~~~~^~~~~~~~~
            
            ソースコード
#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;
}
            
            
            
        