CF1043B.Lost Array

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Bajtek, known for his unusual gifts, recently got an integer array x0,x1,…,xk−1x_0, x_1, \ldots, x_{k-1}.

Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy, Bajtek found on the arrays producer's website another array aa of length n+1n + 1. As a formal description of aa says, a0=0a_0 = 0 and for all other ii (1≤i≤n1 \le i \le n) ai=x(i−1) mod k+ai−1a_i = x_{(i-1)\bmod k} + a_{i-1}, where p mod qp \bmod q denotes the remainder of division pp by qq.

For example, if the x=[1,2,3]x = [1, 2, 3] and n=5n = 5, then:

  • a0=0a_0 = 0,
  • a1=x0 mod 3+a0=x0+0=1a_1 = x_{0\bmod 3}+a_0=x_0+0=1,
  • a2=x1 mod 3+a1=x1+1=3a_2 = x_{1\bmod 3}+a_1=x_1+1=3,
  • a3=x2 mod 3+a2=x2+3=6a_3 = x_{2\bmod 3}+a_2=x_2+3=6,
  • a4=x3 mod 3+a3=x0+6=7a_4 = x_{3\bmod 3}+a_3=x_0+6=7,
  • a5=x4 mod 3+a4=x1+7=9a_5 = x_{4\bmod 3}+a_4=x_1+7=9.

So, if the x=[1,2,3]x = [1, 2, 3] and n=5n = 5, then a=[0,1,3,6,7,9]a = [0, 1, 3, 6, 7, 9].

Now the boy hopes that he will be able to restore xx from aa! Knowing that 1≤k≤n1 \le k \le n, help him and find all possible values of kk — possible lengths of the lost array.

巴杰特以赠送奇特礼物而闻名,最近他得到了一个整数数组 x0,x1,…,xk−1x_0, x_1, \ldots, x_{k-1}。

不幸的是,在与他那些非凡朋友们举办了一场盛大的“数组派对”之后,他意识到自己把该数组弄丢了。在花费数小时寻找新玩具后,巴杰特在数组生产厂商的网站上发现了另一个长度为 n+1n + 1 的数组 aa。根据其形式化描述,有 a0=0a_0 = 0,且对所有其余下标 ii(1≤i≤n1 \le i \le n),满足 ai=x(i−1) mod k+ai−1a_i = x_{(i-1)\bmod k} + a_{i-1},其中 p mod qp \bmod q 表示 pp 除以 qq 所得的余数。

例如,若 x=[1,2,3]x = [1, 2, 3] 且 n=5n = 5,则:

  • a0=0a_0 = 0,
  • a1=x0 mod 3+a0=x0+0=1a_1 = x_{0\bmod 3}+a_0=x_0+0=1,
  • a2=x1 mod 3+a1=x1+1=3a_2 = x_{1\bmod 3}+a_1=x_1+1=3,
  • a3=x2 mod 3+a2=x2+3=6a_3 = x_{2\bmod 3}+a_2=x_2+3=6,
  • a4=x3 mod 3+a3=x0+6=7a_4 = x_{3\bmod 3}+a_3=x_0+6=7,
  • a5=x4 mod 3+a4=x1+7=9a_5 = x_{4\bmod 3}+a_4=x_1+7=9。

因此,当 x=[1,2,3]x = [1, 2, 3] 且 n=5n = 5 时,a=[0,1,3,6,7,9]a = [0, 1, 3, 6, 7, 9]。

现在,这位男孩希望可以从 aa 中恢复出原始数组 xx!已知 1≤k≤n1 \le k \le n,请帮助他找出所有可能的 kk 值——即丢失数组的所有可能长度。

输入格式

The first line contains exactly one integer nn (1≤n≤10001 \le n \le 1000) — the length of the array aa, excluding the element a0a_0.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1061 \le a_i \le 10^6).

Note that a0a_0 is always 00 and is not given in the input.

第一行包含恰好一个整数 nn(1≤n≤10001 \le n \le 1000)—— 表示数组 aa 的长度(不包括元素 a0a_0)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1061 \le a_i \le 10^6)。

注意:a0a_0 恒为 00,且不会在输入中给出。

输出格式

The first line of the output should contain one integer ll denoting the number of correct lengths of the lost array.

The second line of the output should contain ll integers — possible lengths of the lost array in increasing order.

输出的第一行应包含一个整数 ll,表示丢失数组的正确长度的个数。

输出的第二行应包含 ll 个整数——按升序排列的丢失数组所有可能的长度。

输入输出样例

  • 输入#1

    5
    1 2 3 4 5

    输出#1

    5
    1 2 3 4 5
  • 输入#2

    5
    1 3 5 6 8

    输出#2

    2
    3 5
  • 输入#3

    3
    1 5 3

    输出#3

    1
    3

说明/提示

In the first example, any kk is suitable, since aa is an arithmetic progression.

Possible arrays xx:

  • [1][1]
  • [1,1][1, 1]
  • [1,1,1][1, 1, 1]
  • [1,1,1,1][1, 1, 1, 1]
  • [1,1,1,1,1][1, 1, 1, 1, 1]

In the second example, Bajtek's array can have three or five elements.

Possible arrays xx:

  • [1,2,2][1, 2, 2]
  • [1,2,2,1,2][1, 2, 2, 1, 2]

For example, k=4k = 4 is bad, since it leads to 6+x0=86 + x_0 = 8 and 0+x0=10 + x_0 = 1, which is an obvious contradiction.

In the third example, only k=nk = n is good.

Array [1,4,−2][1, 4, -2] satisfies the requirements.

Note that xix_i may be negative.

在第一个例子中,任意 kk 均可取,因为 aa 本身是一个等差数列。

可能的数组 xx 有:

  • [1][1]
  • [1,1][1, 1]
  • [1,1,1][1, 1, 1]
  • [1,1,1,1][1, 1, 1, 1]
  • [1,1,1,1,1][1, 1, 1, 1, 1]

在第二个例子中,Bajtek 的数组长度可以是 3 或 5。

可能的数组 xx 有:

  • [1,2,2][1, 2, 2]
  • [1,2,2,1,2][1, 2, 2, 1, 2]

例如,k=4k = 4 是不合法的,因为它会导致 6+x0=86 + x_0 = 8 和 0+x0=10 + x_0 = 1,这显然矛盾。

在第三个例子中,仅当 k=nk = n 时成立。

数组 [1,4,−2][1, 4, -2] 满足题目要求。

注意:xix_i 可以为负数。

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

首页