結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー MisterMister
提出日時 2020-04-12 05:14:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 797 bytes
コンパイル時間 1,148 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 18:42:06
合計ジャッジ時間 1,897 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}
0