結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー ふーらくたるふーらくたる
提出日時 2016-09-16 12:34:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 1,116 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 76,932 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 14:01:57
合計ジャッジ時間 1,230 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
5,248 KB
testcase_01 AC 54 ms
5,376 KB
testcase_02 AC 31 ms
5,376 KB
testcase_03 AC 57 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <map>
using namespace std;
using Info = pair<int, int>;    // (残存数, 竹の長さ)

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        map<int, int> counter;
        for (int i = 0; i < n; i++) {
            int l;
            cin >> l;

            counter[l]++;
        }

        priority_queue<Info> que;
        for (auto it = counter.begin(); it != counter.end(); it++) {
            Info info = make_pair(it->second, it->first);
            que.push(info);
        }

        int ans = 0;
        while (true) {
            int num = 0;

            vector<Info> temp;
            while (!que.empty() && num < 3) {
                Info info = que.top(); que.pop();
                info.first--;
                num++;

                if (info.first > 0) temp.push_back(info);
            }

            for (auto elt : temp) {
                que.push(elt);
            }

            if (num == 3) ans++;
            else break;
        }
        cout << ans << endl;
    }
    return 0;
}
0