結果

問題 No.2126 MEX Game
ユーザー ripity
提出日時 2022-11-18 23:17:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 197,564 KB
最終ジャッジ日時 2025-02-08 22:26:59
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 20 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N), cnt(100001);
    for( int i = 0; i < N; i++ ) {
        cin >> A[i];
        cnt[A[i]]++;
    }
    bool flag = true, ge_two = false;
    sort(A.begin(), A.end());
    for( int i = 0; i <= 100000; i++ ) {
        if( cnt[i] == 0 ) {
            cout << i << endl;
            break;
        }else if( cnt[i] == 1 ) {
            if( flag ) {
                if( A[N-1] == i ) {
                    if( !ge_two ) {
                        cout << 0 << endl;
                        break;
                    }
                }else {
                    cnt[i]++;
                    cnt[A[N-1]]--;
                }
                flag = true;
            }else {
                cout << i << endl;
            }
        }else {
            ge_two = true;
        }
    }
}
0