結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー dnishdnish
提出日時 2018-06-15 11:38:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 1,067 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 176,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 04:33:36
合計ジャッジ時間 2,415 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) (a)<=(n)&&(n)<(b)
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
typedef long long ll;
using namespace std;
const ll inf =1e18;

int T;
int main(){
    while(cin>>T){
        REP(t,0,T){
            int N;
            cin>>N;
            int ans=0;
            map<int,int> m;
            REP(i,0,N){
                int l;
                cin>>l;
                m[l]++;
            }
            priority_queue<int> pq;
            for(auto mm:m){
                pq.push(mm.second);
            }
            while(pq.size()>2){
                int a=pq.top(); pq.pop();
                int b=pq.top(); pq.pop();
                int c=pq.top(); pq.pop();
                if(c==0) break;
                ans++;
                a--;
                b--;
                c--;
                pq.push(a);
                pq.push(b);
                pq.push(c);
            }
            p(ans);
        }
    }


}
0