CF1054B Appending Mex
题目描述
一开始有一个空的序列,每一次可以选取这个序列的一个子序列,并将这个子序列的 $\text{mex}$ 值加入到序列的尾部。
给定长度为 $n$ 的序列 $a_i$,求最小的 $t$ 使得无法通过若干次操作得到序列 $a_1,\ldots,a_t$。
输入格式
第一行一个正整数 $n$。
第二行 $n$ 个正整数,第 $i$ 个表示 $a_i$。
输出格式
如果可以通过若干次操作得到整个序列输出 $-1$,否则输出最小的 $t$ 使得若干次操作后无法得到 $a_1,\ldots,a_t$。
Translated By Karry5307
说明/提示
In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed.
- $ 1 $ -st step. The initial array is empty. He can choose an empty subset and obtain $ 0 $ , because the mex of an empty set is $ 0 $ . Appending this value to the end he gets the array $ [0] $ .
- $ 2 $ -nd step. The current array is $ [0] $ . He can choose a subset $ [0] $ and obtain an integer $ 1 $ , because $ mex(0) = 1 $ . Appending this value to the end he gets the array $ [0,1] $ .
- $ 3 $ -rd step. The current array is $ [0,1] $ . He can choose a subset $ [0,1] $ and obtain an integer $ 2 $ , because $ mex(0,1) = 2 $ . Appending this value to the end he gets the array $ [0,1,2] $ .
- $ 4 $ -th step. The current array is $ [0,1,2] $ . He can choose a subset $ [0] $ and obtain an integer $ 1 $ , because $ mex(0) = 1 $ . Appending this value to the end he gets the array $ [0,1,2,1] $ .
Thus, he can get the array without mistakes, so the answer is $ -1 $ .
In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from $ 0 $ .
In the third example he could have obtained $ [0, 1, 2] $ without mistakes, but $ 239 $ is definitely wrong.