結果
| 問題 | 
                            No.2126 MEX Game
                             | 
                    
| コンテスト | |
| ユーザー | 
                             buey_t
                         | 
                    
| 提出日時 | 2023-03-17 10:27:04 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,970 bytes | 
| コンパイル時間 | 311 ms | 
| コンパイル使用メモリ | 81,612 KB | 
| 実行使用メモリ | 104,096 KB | 
| 最終ジャッジ日時 | 2024-09-18 09:52:50 | 
| 合計ジャッジ時間 | 5,595 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 WA * 1 | 
ソースコード
def main():
    try:
        import pypyjit
        pypyjit.set_param('max_unroll_recursion=-1')
    except:
        pass
    try:
        import sys
        sys.setrecursionlimit(10**7)
    except:
        pass
    from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
    from heapq import heapify, heappop, heappush
    from bisect import bisect_left, bisect_right
    from copy import deepcopy
    import copy
    import random
    from collections import deque,Counter,defaultdict
    from itertools import permutations,combinations
    from decimal import Decimal,ROUND_HALF_UP
    #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    from functools import lru_cache, reduce
    #@lru_cache(maxsize=None)
    from operator import add,sub,mul,xor,and_,or_,itemgetter
    INF = 10**18
    mod1 = 10**9+7
    mod2 = 998244353
    
    #DecimalならPython
    
    
    '''
    後手が最後
    1個あって、かつ余裕があればよい
    先手終了後、すべて2個以上あればよい
    1個増やせる代わりに一つ消さないといけない
    '''
    
    N = int(input())
    A = list(map(int, input().split()))
    
    memo = [0]*(10**5+2)
    
    for i in range(N):
        memo[A[i]] += 1
    
    tmp = 0
    ans = -1
    f = False
    for i in range(N+1):
        if memo[i] == 0:
            ans = i
            break
        if memo[i] == 1:
            if f:
                ans = i
                break
            else:
                tmp -= 1
                f = True
        if memo[i] == 2:
            continue
        if memo[i] >= 3:
            tmp += 1
    
    for i in range(ans,N+1):
        tmp += memo[i]
    
    if tmp >= 0:
        print(ans)
    else:
        print(ans-1)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
            
            
            
        
            
buey_t