結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー kpinkcatkpinkcat
提出日時 2023-10-26 18:32:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 2,768 ms
コンパイル使用メモリ 212,896 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-26 18:32:27
合計ジャッジ時間 3,540 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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