結果
| 問題 | No.3780 Erase and Mex |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-25 11:11:34 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 210 ms / 2,000 ms |
| + 4µs | |
| コード長 | 1,107 bytes |
| 記録 | |
| コンパイル時間 | 4,196 ms |
| コンパイル使用メモリ | 367,292 KB |
| 実行使用メモリ | 13,604 KB |
| 最終ジャッジ日時 | 2026-11-25 11:11:44 |
| 合計ジャッジ時間 | 7,347 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 43 |
ソースコード
#include <bits/stdc++.h>
#define All(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using ll=long long;
void solve(){
int n;
cin>>n;
vector<int> a(n);
for(auto &x:a) cin>>x;
sort(All(a));
if(n==1) return cout<<max(1,a.back())<<'\n',void();
auto check=[&](int x) -> bool {
int bg=0;
unordered_map<int,int> mp;
for(int i=a.size()-1;i>=0;--i)
if(a[i]<x) mp[a[i]]++;
else ++bg;
mp[0]+=bg;
//bg's 0s, or 1s
int need=1;
for(int i=x-1;i>0;--i){
if(mp[i]>=need) mp[i]-=need;
else{
int tmp=need-mp[i];
mp[i]=0;
need+=tmp;
}
mp[0]+=mp[i];
if(need>n) return false;
}
return need<=mp[0];
};
int L=1,R=n;
while(L<R){
int mid=(L+R+1)>>1;
if(check(mid)) L=mid;
else R=mid-1;
}
cout<<L<<'\n';
}
signed main(){
IOS
int T;
cin>>T;
while(T--){
solve();
}
}