結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー T1610T1610
提出日時 2019-04-05 01:17:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 1,169 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 176,344 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-08-28 13:43:15
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int> v(n);
        rep(i, n) cin >> v[i];
        map<int, int> mp;
        rep(i, n) ++mp[v[i]];
        priority_queue<int> q;
        for(auto&& p : mp) q.push(p.se);
        int ans = 0;
        while(q.size() >= 3) {
            auto a = q.top(); q.pop();
            auto b = q.top(); q.pop();
            auto c = q.top(); q.pop();
            ++ans;
            if(a > 1) q.push(a-1);
            if(b > 1) q.push(b-1);
            if(c > 1) q.push(c-1);
        }
        cout << ans << endl;
    }
    return 0;
}
0