結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー peroonperoon
提出日時 2019-04-05 18:35:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,421 bytes
コンパイル時間 1,084 ms
コンパイル使用メモリ 106,988 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:40:58
合計ジャッジ時間 1,749 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll T;
    cin >> T;

    ll N;

    FOR(t, 0, T){
        cin >> N;

        map<ll, ll> mp;
        FOR(i, 0, N){
            ll a;
            cin >> a;
            mp[a]++;        
        }

        priority_queue<ll> que;
        for(auto p : mp){
            que.push(p.second);
        }

        ll count = 0;
        while(que.size()>=3){
            ll a = que.top(); que.pop();
            ll b = que.top(); que.pop();
            ll c = que.top(); que.pop();

            a--;
            b--;
            c--;
            count++;

            if(a>0) que.push(a);
            if(b>0) que.push(b);
            if(c>0) que.push(c);
        }
        p(count);
    }
    
    return 0;
}
0