結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
5,248 KB
testcase_01 AC 34 ms
5,376 KB
testcase_02 AC 15 ms
5,376 KB
testcase_03 AC 37 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, 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