結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー kyunakyuna
提出日時 2019-07-29 15:50:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 728 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 88,232 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 11:55:07
合計ジャッジ時間 2,247 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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