結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー imulanimulan
提出日時 2016-12-08 16:05:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 175,432 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 02:29:22
合計ジャッジ時間 2,638 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    int T;
    scanf(" %d", &T);
    while(T--)
    {
        int n;
        scanf(" %d", &n);

        map<int,int> ct;
        rep(i,n)
        {
            int L;
            scanf(" %d", &L);
            ++ct[L];
        }

        priority_queue<int> que;
        for(const auto &x:ct) que.push(x.se);

        int ans=0;
        while(que.size()>=3)
        {
            int p[3];
            rep(i,3)
            {
                p[i]=que.top();
                que.pop();
            }
            rep(i,3)
            {
                --p[i];
                if(p[i]>0) que.push(p[i]);
            }
            ++ans;
        }

        printf("%d\n", ans);
    }
    return 0;
}
0