結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-12 05:14:39 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 35 ms / 5,000 ms | 
| コード長 | 797 bytes | 
| コンパイル時間 | 1,695 ms | 
| コンパイル使用メモリ | 83,192 KB | 
| 最終ジャッジ日時 | 2025-01-09 17:37:40 | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using lint = long long;
void solve() {
    std::map<int, int> cnt;
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;
        if (!cnt.count(x)) cnt[x] = 0;
        ++cnt[x];
    }
    int ok = 0, ng = n;
    while (ng - ok > 1) {
        int mid = (ok + ng) / 2;
        int sum = 0;
        for (auto p : cnt) {
            sum += std::min(mid, p.second);
        }
        if (sum >= mid * 3) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    std::cout << ok << std::endl;
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int q;
    std::cin >> q;
    while (q--) solve();
    return 0;
}
            
            
            
        