結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー mayoko_mayoko_
提出日時 2015-01-08 23:36:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 1,079 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 85,032 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 22:42:56
合計ジャッジ時間 1,414 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define INF 1000000000

using namespace std;
typedef long long ll;


int main(void) {
    int T;
    cin >> T;
    while (T--) {
        map<int, int> m;
        int N;
        cin >> N;
        for (int i = 0; i < N; i++) {
            int l;
            cin >> l;
            m[l]++;
        }
        priority_queue<int> que;
        for (auto it = m.begin(); it != m.end(); it++) {
            que.push((*it).second);
        }
        ll ans = 0;
        while (que.size() >= 3) {
            int a = que.top(); que.pop();
            int b = que.top(); que.pop();
            int c = que.top(); que.pop();
            a--; b--; c--;
            if (a > 0) que.push(a);
            if (b > 0) que.push(b);
            if (c > 0) que.push(c);
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}
0