欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1054B.Appending Mex
Appending Mex
Initially Ildar has an empty array. He performs steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array.
The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset is , while the mex of the multiset is .
More formally, on the step , when Ildar already has an array , he chooses some subset of indices $1 \leq i_1 \lt i_2 \lt \ldots \lt i_k \lt m$ (possibly, empty), where , and appends the to the end of the array.
After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array the minimum step such that he has definitely made a mistake on at least one of the steps , or determine that he could have obtained this array without mistakes.
Input
The first line contains a single integer () — the number of steps Ildar made.
The second line contains integers () — the array Ildar obtained.
Output
If Ildar could have chosen the subsets on each step in such a way that the resulting array is , print .
Otherwise print a single integer — the smallest index of a step such that a mistake was made on at least one step among steps .
Note
In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed.
- -st step. The initial array is empty. He can choose an empty subset and obtain , because the
mexof an empty set is . Appending this value to the end he gets the array . - -nd step. The current array is . He can choose a subset and obtain an integer , because . Appending this value to the end he gets the array .
- -rd step. The current array is . He can choose a subset and obtain an integer , because . Appending this value to the end he gets the array .
- -th step. The current array is . He can choose a subset and obtain an integer , because . Appending this value to the end he gets the array .
Thus, he can get the array without mistakes, so the answer is .
In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from .
In the third example he could have obtained without mistakes, but is definitely wrong.
Samples
4
0 1 2 1
-1
3
1 0 1
1
4
0 1 2 239
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |