QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 512 MB 満点: 100

#2866. Forgotten Set

統計

Little Q has posted a bounty on his personal homepage: he is looking for a non-empty set $S$ consisting only of positive integers, where each element does not exceed $n$, and which satisfies some additional conditions.

As is well known, for any positive integer $x$ not exceeding $n$, we can easily calculate the number of ways $f(x)$ to represent $x$ as a sum of elements in $S$. Here, we agree that in any representation, each number can appear multiple times, but the order of the numbers does not matter.

For example, when $S = \{1, 2, 3, 4, 5\}$, we can calculate $f(2) = 2, f(3) = 3, f(4) = 5, f(5) = 7$. As another example, when $S = \{1, 2, 5\}$, we can calculate $f(4) = 3, f(5) = 4, f(6) = 5, f(7) = 6$.

The trouble is that Little Q has forgotten which elements are in $S$. Fortunately, he used a storage device to record all values of $f(i) \pmod p$, and Little Q hopes you can use this information to help him recover the original set $S$.

Specifically, he wants you to find a non-empty set $S$ of positive integers where each element does not exceed $n$, and for any $i = 1, 2, \dots, n$, the number of ways to represent $i$ as a sum of elements in $S$ is equal to $f(i) \pmod p$, where $p$ is a prime number recorded on the storage device. He guarantees that such a set $S$ always exists.

However, Little Q feels that the information he stored is not enough to recover a unique $S$. That is, there may be multiple such sets $S$, so Little Q hopes you can provide the lexicographically smallest solution among all possible solutions.

For two different sets $S_1$ and $S_2$ that satisfy the conditions, we consider $S_1$ to be lexicographically smaller than $S_2$ if and only if there exists a non-negative integer $k$ such that the first $k$ smallest elements of $S_1$ are exactly equal to the first $k$ smallest elements of $S_2$, and either the number of elements in $S_1$ is $k$ and $S_2$ has at least $(k+1)$ elements, or both $S_1$ and $S_2$ have at least $(k+1)$ elements and the $(k+1)$-th smallest element of $S_1$ is smaller than the $(k+1)$-th smallest element of $S_2$.

Input

The first line contains two integers $n$ and $p$, where $p$ is a prime number. The second line contains $n$ integers $f(1), f(2), \dots, f(n)$, as described in the problem statement. It is guaranteed that adjacent integers in each line are separated by exactly one space, and there are no trailing spaces.

Output

You need to output two lines of information to describe the lexicographically smallest solution. The first line contains an integer $m$ ($m > 0$), representing the number of elements in $S$. The second line contains $m$ positive integers $s_1, s_2, \dots, s_m$, representing the sequence obtained by sorting all elements of $S$ in ascending order. You must ensure that adjacent integers in each line are separated by exactly one space, and there are no trailing spaces at the end of each line.

Constraints

For 100% of the data, $1 \le n < 2^{18}$, $10^6 \le p < 2^{30}$, $0 \le f(i) < p$ ($i = 1, 2, \dots, n$).

Test Case $n$ $p$ Special Constraints
1 $n = 5$ $p = 1000003$ None
2 $n \le 20$ Same as max None
3 $n \le 25$ Same as max None
4 $n \le 25$ Same as max None
5 $n \le 5000$ Same as max $s_m \le 40$
6 $n \le 5000$ Same as max $s_m \le 40$
7 $n \le 8000$ $p = 1000003$ None
8 $n \le 8000$ $p = 1000000007$ None
9 $n \le 8000$ Same as max None
10 $n \le 8000$ Same as max $m = s_m$
11 $n \le 8000$ Same as max None
12 $n \le 8000$ Same as max None
13 $n \le 8000$ Same as max None
14 $n \le 8000$ Same as max None
15 $n \le 8000$ $p = 998244353$ None
16 $n \le 8000$ $p = 991668907$ None
17 $n \le 8000$ $p = 1000000007$ None
18 $n \le 8000$ Same as max None
19 $n \le 8000$ Same as max None
20 $n \le 8000$ Same as max None

Examples

Input 1

5 1000003
1 2 3 5 7

Output 1

5
1 2 3 4 5

Input 2

9 1000003
1 2 2 3 4 5 6 7 8

Output 2

3
1 2 5

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.