CF1415D.XOR-gun
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Arkady owns a non-decreasing array a1,a2,…,an. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.
In one step you can select two consecutive elements of the array, let's say x and y, remove them from the array and insert the integer x⊕y on their place, where ⊕ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.
For example, if the array is [2,5,6,8], you can select 5 and 6 and replace them with 5⊕6=3. The array becomes [2,3,8].
You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print −1.
阿尔卡季拥有一组非递减数组 a1,a2,…,an。你嫉妒它的优美,想破坏这一性质。你拥有一把所谓的“异或枪”,可以使用一次或多次。
每一步中,你可以选择数组中两个相邻的元素,记为 x 和 y,将它们从数组中移除,并在原位置插入整数 x⊕y,其中 ⊕ 表示按位异或运算。注意:该操作会使数组长度减少 1。当数组长度变为 1 时,不能再执行此操作。
例如,若数组为 [2,5,6,8],你可以选择 5 和 6 并将其替换为 5⊕6=3,数组变为 [2,3,8]。
你的目标是使数组不再保持非递减性质。问:所需的最少操作步数是多少?如果无论怎么操作,数组始终维持非递减性质,则输出 −1。
输入格式
The first line contains a single integer n (2≤n≤105) — the initial length of the array.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array. It is guaranteed that ai≤ai+1 for all 1≤i<n.
第一行包含一个整数 n(2≤n≤105)—— 数组的初始长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 数组的元素。保证对所有 1≤i<n,均有 ai≤ai+1。
输出格式
Print a single integer — the minimum number of steps needed. If there is no solution, print −1.
输出一个整数——所需的最少步数。若无解,则输出 −1。
输入输出样例
输入#1
4 2 5 6 8
输出#1
1
输入#2
3 1 2 3
输出#2
-1
输入#3
5 1 2 4 6 20
输出#3
2
说明/提示
In the first example you can select 2 and 5 and the array becomes [7,6,8].
In the second example you can only obtain arrays [1,1], [3,3] and [0] which are all non-decreasing.
In the third example you can select 1 and 2 and the array becomes [3,4,6,20]. Then you can, for example, select 3 and 4 and the array becomes [7,6,20], which is no longer non-decreasing.
在第一个例子中,你可以选择 2 和 5,数组变为 [7,6,8]。
在第二个例子中,你只能得到数组 [1,1]、[3,3] 和 [0],它们都是非递减的。
在第三个例子中,你可以选择 1 和 2,数组变为 [3,4,6,20]。接着,例如你可以选择 3 和 4,数组变为 [7,6,20],该数组不再是非递减的。
输入解题思路,AI测评打分。不知道怎么写?