結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー ninoinuininoinui
提出日時 2020-11-21 22:11:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 958 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 202,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 22:19:42
合計ジャッジ時間 2,883 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    multiset<int> MS;
    for (int i = 0; i < N; i++) {
      int L;
      cin >> L;
      MS.insert(L);
    }

    int ans = 0, now = -1;
    while (MS.size()) {
      auto it = --MS.end();
      now = *it;
      MS.erase(it);
      
      if (!MS.size()) break;
      
      it = MS.lower_bound(now);
      if (it == MS.begin()) break;
      it--;
      now = *it;
      MS.erase(it);
      
      if (!MS.size()) break;
      
      it = MS.lower_bound(now);
      if (it == MS.begin()) break;
      it--;
      now = *it;
      MS.erase(it);
      ans++;
    }
    cout << ans << "\n";
  }
}
0