結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー rogi52rogi52
提出日時 2022-10-04 20:30:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 2,997 ms
コンパイル使用メモリ 208,068 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-28 21:12:20
合計ジャッジ時間 2,757 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

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 -= c; b -= c;
            ans += c;
            if(a > 0) pq.push(a);
            if(b > 0) pq.push(b);
        }
        cout << ans << "\n";
    }
}
0