結果

問題 No.2126 MEX Game
ユーザー FromBooskaFromBooska
提出日時 2023-03-06 14:51:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,593 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 83,448 KB
最終ジャッジ日時 2023-10-18 05:09:51
合計ジャッジ時間 4,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,292 KB
testcase_01 AC 38 ms
54,292 KB
testcase_02 AC 38 ms
54,292 KB
testcase_03 AC 38 ms
54,292 KB
testcase_04 AC 37 ms
54,292 KB
testcase_05 AC 39 ms
54,292 KB
testcase_06 AC 39 ms
54,292 KB
testcase_07 AC 39 ms
54,292 KB
testcase_08 AC 39 ms
54,292 KB
testcase_09 AC 39 ms
54,292 KB
testcase_10 AC 80 ms
83,296 KB
testcase_11 AC 81 ms
83,296 KB
testcase_12 AC 81 ms
83,448 KB
testcase_13 AC 82 ms
83,448 KB
testcase_14 AC 80 ms
83,260 KB
testcase_15 AC 79 ms
83,260 KB
testcase_16 AC 79 ms
81,148 KB
testcase_17 AC 79 ms
82,916 KB
testcase_18 AC 79 ms
83,052 KB
testcase_19 AC 58 ms
79,416 KB
testcase_20 AC 58 ms
79,416 KB
testcase_21 AC 79 ms
83,260 KB
testcase_22 AC 38 ms
54,292 KB
testcase_23 AC 38 ms
54,292 KB
testcase_24 AC 38 ms
54,292 KB
testcase_25 AC 38 ms
54,292 KB
testcase_26 AC 38 ms
54,292 KB
testcase_27 AC 38 ms
54,292 KB
testcase_28 AC 38 ms
54,292 KB
testcase_29 AC 38 ms
54,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 先手後手は繰り返すだけなので2回を考えればいい
# 先手が終わって0が1個だけなら後手はその0を変えてmexを0にできる
# ということは先手が終わった段階で2個ずつある数字までが先手が守れる
# たとえば先手が終わって2個ずつが5まであれば答えは6になる
# Counter(A)して、0から2個づつあればいい、なければ1回だけ最後の数字を持ってこれる
# 全部の数字が2個ずつあった場合はその次の数字がMEXになることに注意
# たとえば0が4個あった場合は、2個を他に変えてもいい
# 全部2個ずつあるなら先手は同じ数字に変える、つまり変えなくていい

N = int(input())
A = list(map(int, input().split()))
A.sort()
maxA = A[-1]

counted = [0]*(10**5+1)
for a in A:
    counted[a] += 1
mex = 10**5+1
smaller_to_use = 0
sente_change = 1
for i in range(0, 10**5+2):
    count = counted[i]
    if count == 0:
        mex = i
        break
    elif count == 1:
        if sente_change == 0:
            mex = i
            break
        else:
            if smaller_to_use == 1:
                smaller_to_use -= 1
                sente_change = 0
            else:
                if i != maxA:
                    counted[maxA] -= 1
                    sente_change = 0
                elif i == maxA:
                    mex = i
                    break
    elif count == 2:
        pass
    elif count > 2:
        if smaller_to_use == 0 and sente_change == 1:
            smaller_to_use += 1
            
print(mex)
0