P27756 [洛谷] 【MX-X2-T3】「Cfz Round 4」Ninelie
提高-
题目描述

Problem Description

Given a sequence of length $n$ consisting of $0$s and $1$s, denoted as $a_1, \ldots, a_n$, and a positive integer $r$.

You can perform operations on the sequence $a$. Each operation involves selecting an index $p$ that satisfies $p = 1$ or $p = n$ or $a_{p-1} \neq a_{p+1}$, and then flipping $a_p$ (changing $0$ to $1$ and $1$ to $0$).

Your task is to transform the sequence $a$ into all $0$s or all $1$s within $r$ operations. You do not need to minimize the number of operations. If it is not possible to achieve this, you must report that it is unsolvable.

The data guarantees that $\bm{r = 2 \times 10^6}$ or $\bm{10^6}$, see the [Data Range] section for details.

Input Format

The first line contains two positive integers $n$ and $r$.

The second line contains $n$ integers $a_1, \ldots, a_n$.

Output Format

If it is not possible to transform the sequence $a$ into all $0$s or all $1$s within $r$ operations, output a single line containing the integer $-1$.

If a solution exists, output two lines:

  • The first line contains a non-negative integer $m$, representing the number of operations; you need to ensure $m \le r$, and you do not need to minimize $m$.
  • The second line contains $m$ positive integers, representing the indices $p$ of each operation in order.

Sample Input and Output

Sample Input #1

4 1000000
0 0 1 0

Sample Output #1

3
2 4 1

Sample Input #2

5 1000000
1 1 1 1 1

Sample Output #2

0

Sample Input #3

10 1000000
0 1 0 0 1 1 0 0 1 0

Sample Output #3

18
1 2 10 1 9 4 10 4 7 4 7 3 7 8 9 2 10 1

Notes

[Sample Explanation #1]

The sequence $a$ after each operation is as follows:

  • $[0,1,1,0]$;
  • $[0,1,1,1]$;
  • $[1,1,1,1]$.

At this point, all elements in the sequence $a$ are the same.

[Data Range]

For all test cases, $2 \le n \le 2 \times 10^3$, $a_i \in \{0,1\}$, and $r = 2 \times 10^6$ or $10^6$.

This problem is bundled test cases.

  • Subtask 1 (20 points): $n \le 10$, $r = 2 \times 10^6$.
  • Subtask 2 (30 points): $r = 2 \times 10^6$.
  • Subtask 3 (50 points): $r = 10^6$.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 1000000 0 0 1 0
样例输出
3 2 4 1