結果

問題 No.3780 Erase and Mex
コンテスト
ユーザー テナガザル
提出日時 2026-10-30 23:48:18
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 775 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,340 ms
コンパイル使用メモリ 172,744 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-10-30 23:48:27
合計ジャッジ時間 7,323 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int l = 0, r = n + 10;
  while (r - l > 1)
  {
    int mid = (l + r) / 2;
    vector<int> cnt(mid + 3);
    for (int i = 0; i < n; ++i) ++cnt[(a[i] >= mid ? 1 : max(a[i], 1))];
    int sum = 0, s0 = 0;
    for (int i = mid - 1; i > 0; --i)
    {
      int tmp = min(sum + 1, cnt[i]);
      int val = sum + 1 - tmp;
      s0 += cnt[i] - tmp;
      sum += val;
      if (sum > n) sum = n + 1;
    }
    // cout << mid << ": " << (sum) << ',' << (cnt[0] + s0) << endl;
    (sum <= cnt[0] + s0 ? l : r) = mid;
  }
  cout << l << endl;
}

int main()
{
  int t;
  cin >> t;
  while (t--) solve();
}
0