CF1848F.Vika and Wiki

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Recently, Vika was studying her favorite internet resource - Wikipedia.

On the expanses of Wikipedia, she read about an interesting mathematical operation bitwise XOR, denoted by ⊕\oplus.

Vika began to study the properties of this mysterious operation. To do this, she took an array aa consisting of nn non-negative integers and applied the following operation to all its elements at the same time: ai=ai⊕a(i+1) mod na_i = a_i \oplus a_{(i+1) \bmod n}. Here x mod yx \bmod y denotes the remainder of dividing xx by yy. The elements of the array are numbered starting from 00.

Since it is not enough to perform the above actions once for a complete study, Vika repeats them until the array aa becomes all zeros.

Determine how many of the above actions it will take to make all elements of the array aa zero. If this moment never comes, output −1-1.

最近,维卡正在学习她最喜欢的网络资源——维基百科。

在维基百科的广阔内容中,她了解了一种有趣的数学运算:按位异或(bitwise XOR),记作 ⊕\oplus。

维卡开始研究这一神秘运算的性质。为此,她取了一个由 nn 个非负整数组成的数组 aa,并对其中所有元素同时执行如下操作:ai=ai⊕a(i+1) mod na_i = a_i \oplus a_{(i+1) \bmod n}。此处 x mod yx \bmod y 表示 xx 除以 yy 的余数。数组元素的编号从 00 开始。

由于仅执行一次上述操作不足以完成全面研究,维卡不断重复该操作,直到数组 aa 中所有元素均变为 00。

请确定需要执行多少次上述操作才能使数组 aa 的所有元素都变为 00。若该状态永远无法达到,则输出 −1-1。

输入格式

The first line contains a single integer nn (1≤n≤2201 \le n \le 2^{20}) - the length of the array aa.

It is guaranteed that nn can be represented as 2k2^k for some integer kk (0≤k≤200 \le k \le 20).

The second line contains nn integers a0,a1,a2,…,an−1a_0, a_1, a_2, \dots, a_{n-1} (0≤ai≤1090 \le a_i \le 10^9) - the elements of the array aa.

第一行包含一个整数 nn(1≤n≤2201 \le n \le 2^{20})——数组 aa 的长度。

保证 nn 可表示为 2k2^k 的形式,其中 kk 为某个整数(0≤k≤200 \le k \le 20)。

第二行包含 nn 个整数 a0,a1,a2,…,an−1a_0, a_1, a_2, \dots, a_{n-1}(0≤ai≤1090 \le a_i \le 10^9)——数组 aa 的元素。

输出格式

Output a single number - the minimum number of actions required to make all elements of the array aa zero, or −1-1 if the array aa will never become zero.

输出一个整数——使数组 aa 的所有元素变为零所需的最少操作次数;如果数组 aa 永远无法全部变为零,则输出 −1-1。

输入输出样例

  • 输入#1

    4
    1 2 1 2

    输出#1

    2
  • 输入#2

    2
    0 0

    输出#2

    0
  • 输入#3

    1
    14

    输出#3

    1
  • 输入#4

    8
    0 1 2 3 4 5 6 7

    输出#4

    5

说明/提示

In the first example, after one operation, the array aa will become equal to [3,3,3,3][3, 3, 3, 3]. After one more operation, it will become equal to [0,0,0,0][0, 0, 0, 0].

In the second example, the array aa initially consists only of zeros.

In the third example, after one operation, the array aa will become equal to [0][0].

在第一个例子中,经过一次操作后,数组 aa 将变为 [3,3,3,3][3, 3, 3, 3];再经过一次操作后,它将变为 [0,0,0,0][0, 0, 0, 0]。

在第二个例子中,数组 aa 初始时仅由零组成。

在第三个例子中,经过一次操作后,数组 aa 将变为 [0][0]。

输入解题思路,AI测评打分。不知道怎么写?

首页