結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー ninoinuininoinui
提出日時 2020-11-22 04:05:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 860 bytes
コンパイル時間 2,620 ms
コンパイル使用メモリ 210,568 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 22:25:13
合計ジャッジ時間 3,728 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,380 KB
testcase_01 AC 25 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>
using namespace std;

template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); }
template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) cin >> L.at(i);

    map<int, int> MA;
    for (auto a : L) MA[a]++;

    priority_queue<int> PQ;
    for (auto [a, b] : MA) PQ.push(b);

    int ans = 0;
    while (PQ.size() >= 3) {
      int a = PQ.top(); PQ.pop();
      int b = PQ.top(); PQ.pop();
      int c = PQ.top(); PQ.pop();
      a--;
      if (a) PQ.push(a);
      b--;
      if (b) PQ.push(b);
      c--;
      if (c) PQ.push(c);
      ans++;
    }
    cout << ans << "\n";
  }
}
0