結果

問題 No.2126 MEX Game
コンテスト
ユーザー detteiuu
提出日時 2026-05-07 23:57:01
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 500 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 278 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 82,816 KB
最終ジャッジ日時 2026-05-07 23:57:07
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
A = list(map(int, input().split()))

B = [0]*(10**5+1)
for a in A:
    B[a] += 1
MEX = -1
for i in range(10**5+1):
    if B[i] == 0:
        MEX = i
        B = B[:i]
        break
if MEX == 0:
    exit(print(MEX))

if 2 <= min(B):
    print(MEX)
elif B.count(1) == 1:
    if 3 <= max(B) or sum(B) < N:
        print(MEX)
    else:
        print(MEX-1)
else:
    cnt = 0
    for i in range(len(B)):
        cnt += B[i] == 1
        if cnt == 2:
            print(i)
            break
0