結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-05-21 17:44:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 63 ms / 5,000 ms | 
| コード長 | 873 bytes | 
| コンパイル時間 | 898 ms | 
| コンパイル使用メモリ | 87,264 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-28 15:29:22 | 
| 合計ジャッジ時間 | 1,588 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
#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;
}
            
            
            
        