結果

問題 No.3780 Erase and Mex
コンテスト
ユーザー tnakao0123
提出日時 2026-10-31 20:59:12
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,013 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 232 ms
コンパイル使用メモリ 58,344 KB
実行使用メモリ 9,928 KB
最終ジャッジ日時 2026-10-31 20:59:21
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3780.cc:  No.3780 Erase and Mex - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

using ll = long long;

/* global variables */

int as[MAX_N], cs[MAX_N + 2];

/* subroutines */

bool check(int n, int x) {
  ll c0 = cs[0], d = 1;
  for (int i = n + 1; i > 0; i--) {
    if (i > x) c0 += cs[i];
    else {
      if (cs[i] >= d) c0 += cs[i] - d;
      else d += d - cs[i];
    }
  }
  return c0 >= d;
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", as + i);

    if (n == 1) { printf("%d\n", max(1, as[0])); continue; }

    fill(cs, cs + n + 2, 0);
    for (int i = 0; i < n; i++) cs[min(n + 1, as[i])]++;
    
    int x0 = 0, x1 = n;
    while (x0 + 1 < x1) {
      int x = (x0 + x1) / 2;
      if (check(n, x)) x0 = x;
      else x1 = x;
    }
    
    printf("%d\n", x1);
  }

  return 0;
}
0