結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー tottoripapertottoripaper
提出日時 2015-03-05 21:42:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 834 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 72,704 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 13:47:05
合計ジャッジ時間 1,185 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <queue>
#include <unordered_map>

std::priority_queue<int> q;
std::unordered_map<int,int> m;

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

    while(T--){
        while(!q.empty()){q.pop();}
        m.clear();
        
        int N;
        scanf("%d", &N);
        
        for(int i=0;i<N;i++){
            int l;
            scanf("%d", &l);

            m[l]++;
        }

        for(const auto& p : m){
            q.push(p.second);
        }

        int res = 0;
        while(q.size() >= 3){
            res++;
            
            int xs[3];
            for(int i=0;i<3;i++){
                xs[i] = q.top();
                q.pop();
            }

            for(int i=0;i<3;i++){
                if(xs[i] > 1){q.push(xs[i]-1);}
            }
        }

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