結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-02-08 20:52:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 1,317 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 89,348 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 06:12:41
合計ジャッジ時間 1,999 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int T;
    cin >> T;

    vector<int> Ans;

    int N;
    for ( int i = 0; i < T; i++ ) {
        int ans = 0;

        cin >> N;
        vector<long long> L(N);

        for ( int j = 0; j < N; j++ ) {            
            cin >> L[j];
        }
        sort( L.begin(), L.end() );

        int cnt = 1;
        priority_queue<int> A;

        for ( int j = 1; j < N; j++ ) {            
            if ( L[j] == L[j-1] ) { cnt++; }
            else { A.push(cnt); cnt = 1; }
        }
        A.push(cnt);

        while ( A.size() >= 3 ) {            
            ans++;
            int a[3];
            for (int j = 0; j < 3; j++ ) {
                a[j] = A.top() - 1;
                A.pop();
            }
            for (int j = 0; j < 3; j++ ) {
                if ( a[j] != 0 ) {
                    A.push( a[j] );
                }
            }
        }

        Ans.push_back(ans);
    }
    
    for ( int i = 0; i < T; i++ ) {
        cout << Ans[i] << endl;
    }


    return 0;
}
0