結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー satanicsatanic
提出日時 2016-04-23 18:03:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 1,094 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 88,152 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 07:23:19
合計ジャッジ時間 1,541 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#include <utility>
#include <algorithm>

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int t;
    std::cin >> t;
    for(int i=0; i<t; ++i){
        int n;
        std::cin >> n;
        std::map<int, int> lNumMap;
        for(int j=0; j<n; ++j){
            int input;
            std::cin >> input;
            ++lNumMap[input];
        }
        std::vector<std::pair<int, int>> lNumPair(2, std::make_pair(0, 0));
        for(auto it=lNumMap.begin(); it!=lNumMap.end(); ++it){
            lNumPair.push_back(std::make_pair(it->first, it->second));
        }
        int ans = 0;
        while(true){
            std::sort(lNumPair.begin(), lNumPair.end(), [](const std::pair<int, int>& l, const std::pair<int, int>& r){
                return l.second>r.second;
            });
            if(lNumPair[2].second==0) break;
            for(int j=0; j<3; ++j){
                --lNumPair[j].second;
            }
            ++ans;
        }
        std::cout << ans << "\n";
    }
        
    return 0;
}
0