結果

問題 No.2126 MEX Game
ユーザー HIcoder
提出日時 2023-07-11 11:17:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,498 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 100,176 KB
最終ジャッジ日時 2025-02-15 09:43:07
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);


int main(){
    int N;
    cin>>N;

    const int MAXN=100000;
    vector<int> cnt(100000+10,0);
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        cnt[A[i]]++;
    }

    int last=-1;
    for(int i=0;i<=MAXN;i++){
        if(cnt[i]==0){
            last=i;
            break;
        }
    }

    bool flag=false;
    for(int i=0;i<last;i++){
        if(cnt[i]<2){
            flag=true;
        }
    }

    if(!flag){
        cout<<last<<endl;
        return 0;
    }
    

    bool flag2=true;
    int cnt1=0;
    for(int i=0;i<last;i++){
        if(cnt[i]==1){
            cnt1++;
        }
        else if(cnt[i]==0){
            flag2=false;
        }
    }

    if(cnt1>1)flag2=false;

    if(flag2){
        bool flag3=false;
        for(int i=0;i<last;i++){
            if(cnt[i]>2)flag3=true;
        }

        for(int i=last;i<=MAXN;i++){
            if(cnt[i]>=1)flag3=true;
        }

        if(flag3){
            cout<<last<<endl;
        }else{
            cout<<last-1<<endl;
        }
        // cout<<"te"<<endl;

        // cout<<last<<endl;
    }else{
        //cout<<"ter"<<endl;
        cout<<last-1<<endl;
    }



}
0