結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-17 14:39:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 746 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 178,148 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 22:36:29
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N;
        map<int, int> cnt;
        cin >> N;
        while (N--) {
            int L;
            cin >> L;
            cnt[L]++;
        }

        priority_queue<int> que;
        for (auto& p : cnt)
            que.push(p.second);

        int ans = 0;

        while (que.size() >= 3) {
            int a[3] = {};
            for (int i = 0; i < 3; i++) {
                a[i] = que.top();
                que.pop();
            }
            for (int i = 0; i < 3; i++) {
                if (a[i] > 1)
                    que.push(a[i] - 1);
            }
            ans++;
        }

        cout << ans << endl;
    }
}
0