結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-03-28 01:52:29 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 24 ms / 5,000 ms | 
| コード長 | 1,267 bytes | 
| コンパイル時間 | 1,573 ms | 
| コンパイル使用メモリ | 168,544 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-02 05:40:32 | 
| 合計ジャッジ時間 | 2,219 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int sol(priority_queue< pair<int, int> >& pq){
    int ans = 0;
    pair<int, int> x[3];
    while(!pq.empty()) {
        for(int i = 0; i < 3; i++) {
            if(pq.empty()) return ans;
            x[i] = pq.top();
            pq.pop();
        }
        for(int i = 0; i < 3; i++) {
            if (x[i].first > 1) {
                x[i].first--;
                pq.push(x[i]);
            }
        }
        ans++;
    }
    return ans;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t, n, tmp = 0, count = 1;
    cin >> t;
    for(int i = 0; i < t; i++) {
        cin >> n;
        vector<int> a(n);
        priority_queue< pair<int, int> > pq;
        for(int j = 0; j < n; j++) {
            cin >> a[j];
        }
        sort(a.begin(), a.end());
        for(int j = 0; j < n; j++) {
            if (tmp == 0) {
                tmp = a[j];
            } else if (tmp == a[j]) {
                count++;
            } else {
                pq.push(make_pair(count, tmp));
                tmp = a[j];
                count = 1;
            }
        }
        pq.push(make_pair(count, tmp));
        tmp = 0;
        count = 1;
        cout << sol(pq) << "\n";
    }
    return 0;
}
            
            
            
        