結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー utouto97utouto97
提出日時 2019-03-21 21:55:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,072 bytes
コンパイル時間 2,989 ms
コンパイル使用メモリ 172,404 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 05:42:26
合計ジャッジ時間 3,794 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
  int t;
  cin >> t;

  while(t--){
    int n;
    cin >> n;

    vi L(n);
    map<int, int> cnt;
    rep(i, n){
      cin >> L[i];
      cnt[L[i]]++;
    }

    if(cnt.size() < 3){
      cout << 0 << endl;
      continue;
    }

    priority_queue<int> que;
    for(auto it : cnt){
      que.push(it.second);
    }

    int ans = 0;
    while(1){
      int a = que.top(); que.pop();
      int b = que.top(); que.pop();
      int c = que.top(); que.pop();
      if(c <= 0){
        break;
      }
      ans++;
      que.push(a-1);
      que.push(b-1);
      que.push(c-1);
    }
    cout << ans << endl;
  }

  return 0;
}
0