結果

問題 No.3780 Erase and Mex
コンテスト
ユーザー askr58
提出日時 2026-07-20 02:25:05
言語 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  
(最新)
AC  
(最初)
実行時間 -
コード長 944 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,344 ms
コンパイル使用メモリ 188,812 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-10-30 20:50:57
合計ジャッジ時間 5,469 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <numeric>
#include <ranges>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;
using ll=long long;
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int ttt;
	cin>>ttt;
	assert(1<=ttt&&ttt<=200000);
	ll sum=0;
	while(ttt--){
		int n;
		cin>>n;
		assert(1<=n&&n<=200000);
		sum+=n;
		vector<int> a(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
			assert(0<=a[i]&&a[i]<=1000000000);
		}
		if(n==1){
			cout<<max(a[0],1)<<endl;
			return 0;
		}
		vector<int> cnt(n);
		for(int i=0;i<n;i++){
			if(a[i]>=n)cnt[0]++;
			else cnt[a[i]]++;
		}
		int l=0,r=n+1;
		while(l+1<r){
			int c=(l+r)/2;
			ll need=1;
			vector<int> b=cnt;
			for(int i=c;i<n;i++)b[0]+=b[i];
			for(int i=c-1;i>=1;i--){
				if(b[i]>=need){
					b[0]+=b[i]-need;
				}else{
					need+=(need-b[i]);
				}
				if(need>n)break;
			}
			if(need<=b[0])l=c;
			else r=c;
		}
		cout<<l<<endl;
	}
	assert(sum<=200000);
}
0