結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー kpinkcat
提出日時 2023-10-26 18:32:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 204,008 KB
最終ジャッジ日時 2025-02-17 13:50:31
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;


int main(){
    int t;
    cin >> t;
    priority_queue<int> pq;
    for (int i = 0; i < t; i++) {
        int t1, ans = 0, al1 = 0;
        cin >> t1;
        map<int, int> mp;
        for (int j = 0; j < t1; j++){
            int t2;
            cin >> t2;
            mp[t2]++;
        }

        for (auto itr = mp.begin(); itr != mp.end(); itr++){
            pq.push(itr->second);
        }
        while (pq.size() >= 3){
            ll a, b, c;
            
            a = pq.top();
            pq.pop();
            b = pq.top();
            pq.pop();
            c = pq.top();
            pq.pop();
            if (c <= 0) break;
            ans++;
            pq.push(a-1);
            pq.push(b-1);
            pq.push(c-1);            
        }
        cout << ans << endl;
    }
}
0