QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#16537. Ninelie

Statistiques

Background

The melody resonates endlessly along one side, flowing through the streets before my eyes, accompanied by a fading love that drifts further and further away.

The unattainable ideal composition gradually twists; the silent resistance awakens at this moment, and the impulse arrives late as well.

Fragmented cries and beautiful dreams; the ideal is left with nothing but a decorative facade.

Even if the city is happy to be drowned in noise and clamor,

I will continue to sing loudly, abandoning everything that controls me.

So I only wish for that tranquility to resonate once more.

Fear not, for the dawn has already arrived.

Description

Given a $01$ sequence $a_1, \ldots, a_n$ of length $n$ and a positive integer $r$.

You can perform operations on the sequence $a$. In each operation, you must choose an index $p$ such that $p=1$, $p=n$, or $a_{p-1} \neq a_{p+1}$, and then flip $a_p$ (i.e., change $0$ to $1$ or $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 impossible, you must report that there is no solution.

The data guarantees that $\boldsymbol{r = 2 \times 10^6}$ or $\boldsymbol{10^6}$; please refer to the "Constraints" section for specific details.

Input

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

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

Output

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

If a construction exists, output two lines:

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

Examples

Input 1

4 1000000
0 0 1 0

Output 1

3
2 4 1

Note 1

The sequence $a$ after each operation is:

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

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

Input 2

5 1000000
1 1 1 1 1

Output 2

0

Input 3

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

Output 3

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

Constraints

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

This problem uses bundled testing.

  • 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$.

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.