結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー kyuna
提出日時 2019-07-29 15:50:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 728 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 87,876 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 15:22:24
合計ジャッジ時間 1,988 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int main() {
    int T; cin >> T;
    while (T--) {
        int n; cin >> n;
        map<int, int> cnt;
        while (n--) { int l; cin >> l; cnt[l]++; }
        priority_queue<int> pq;
        for (auto &p: cnt) pq.emplace(p.second);
        int ans = 0;
        while (pq.size() >= 3) {
            int a = pq.top(); pq.pop();
            int b = pq.top(); pq.pop();
            int c = pq.top(); pq.pop();
            ans++;
            if (a - 1) pq.emplace(a - 1);
            if (b - 1) pq.emplace(b - 1);
            if (c - 1) pq.emplace(c - 1);
        }
        cout << ans << endl;
    }
    return 0;
}
0