結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー face4face4
提出日時 2018-05-21 17:44:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 873 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 86,184 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 00:57:35
合計ジャッジ時間 1,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;

int main(){
    int t;
    cin >> t;

    while(t-- > 0){
        int n, x;
        cin >> n;

        map<int,int> cnt;
        for(int i = 0; i < n; i++){
            cin >> x;
            cnt[x]++;
        }

        vector<int> counts;
        for(map<int,int>::iterator it = cnt.begin(); it != cnt.end(); it++){
            counts.push_back((*it).second);
        }        

        sort(counts.begin(), counts.end());
        
        int ans = 0;
        int len = counts.size();
        
        while(len >= 3){
            if(counts[len-3] == 0)  break;
            ans++;
            counts[len-1]--;
            counts[len-2]--;
            counts[len-3]--;
            sort(counts.begin(), counts.end());
        }

        cout << ans << endl;
    }

    return 0;
}
0