結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー rogi52rogi52
提出日時 2022-10-04 20:32:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 2,946 ms
コンパイル使用メモリ 209,424 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 21:14:17
合計ジャッジ時間 3,586 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int T; cin >> T;
    rep(_,T) {
        int N; cin >> N;
        map<int,int> mp;
        rep(i,N) {
            int L; cin >> L;
            mp[L]++;
        }

        priority_queue<int> pq;
        for(auto [_, c] : mp) pq.push(c);
        int ans = 0;
        while(int(pq.size()) >= 3) {
            int a = pq.top(); pq.pop();
            int b = pq.top(); pq.pop();
            int c = pq.top(); pq.pop();
            a--; b--; c--;
            ans++;
            if(a > 0) pq.push(a);
            if(b > 0) pq.push(b);
            if(c > 0) pq.push(c);
        }
        cout << ans << "\n";
    }
}
0