結果

問題 No.3780 Erase and Mex
コンテスト
ユーザー GOTKAKO
提出日時 2026-10-30 21:54:06
言語 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
結果
AC  
実行時間 16 ms / 2,000 ms
+ 745µs
コード長 1,364 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,417 ms
コンパイル使用メモリ 218,616 KB
実行使用メモリ 9,852 KB
最終ジャッジ日時 2026-10-30 21:54:13
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

    int T; cin >> T;
    while(T--){
        int N; cin >> N;
        if(N == 1){int x; cin >> x; cout << max(1,x) << "\n"; continue;} //おお

        vector<int> C(N+1);
        for(int i=0; i<N; i++){
            int a; cin >> a;
            if(a > N) C.at(N)++;
            else C.at(a)++;
        }

        int low = 0,high = N+1;
        while(high-low > 1){
            int mid = (high+low)/2;
            int free = 0,need = 1;
            for(int i=mid; i<=N; i++) free += C.at(i);

            bool ok = true;
            for(int i=mid; i--;){
                if(i > 1){
                    if(need <= C.at(i)) free += C.at(i)-need;
                    else need += need-C.at(i);
                    if(need > 1001001){ok = false; break;}
                }
                else if(i == 1){
                    if(need <= C.at(i)) free += C.at(i)-need;
                    else free -= need-C.at(i);
                }
                else{
                    if(need <= C.at(i)) free += C.at(i)-need;
                    else free -= need-C.at(i);
                    if(free < 0) ok = false;
                }
            }
            if(ok) low = mid;
            else high = mid;
        }
        cout << low << "\n";
    }
}
0