QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#5167. Magician

统计

King is a magician who can always accomplish incredible things using simple principles.

King has a stack of $n$ playing cards, all face down. King has assigned a unique number between $1$ and $n$ to each card. Initially, the number on the $i$-th card from the top is $p_i$. While performing a magic trick, King performs several operations such that the number on the $i$-th card from the top is exactly $i$.

To make the magic effect more deceptive, King only performs actions that appear ordinary. Omitting the specific sleight of hand, one operation by King can be simplified into the following steps:

  1. Take a stack of cards from the top of the deck and place them on the table; this is called stack A (it can be empty).
  2. Deal $m$ cards one by one from the top of the remaining deck onto the table, face down, to form stack B.
  3. Place stack B back on top of the deck.
  4. Place stack A back on top of the deck.

Please help King provide an operation sequence, or tell King that no such sequence exists.

Input

The first line contains three integers $T, n, m$, representing the test package ID, the number of cards in the deck, and the number of cards dealt in each operation.

The second line contains $n$ integers $p_1, p_2, \ldots, p_n$, representing the number on each card from top to bottom.

Output

If no operation sequence exists, output $-1$. Otherwise:

The first line contains a non-negative integer $k$, representing the number of operations.

The next $k$ lines each contain a non-negative integer $c_i\ (0 \le c_i \le n-m)$, representing the number of cards in stack A for the $i$-th operation.

Examples

Input 1

0 8 4
6 2 5 1 7 4 3 8

Output 1

4
0
2
3
1

Input 2

0 6 5
3 4 1 5 6 2

Output 2

-1

Subtasks

Each test package comes with parameters $lim_1, lim_2, \ldots, lim_5$. Let $S$ be the score of a test package. For the test cases within that package, the scoring is as follows:

  • If the test case has no solution:
    • If the participant outputs a solution, they get $0$ points.
    • Otherwise, they get $S$ points.
  • If the test case has a solution:
    • If the participant outputs that there is no solution or the provided sequence is invalid, they get $0$ points.
    • Otherwise, let $k$ be the number of operations in the participant's sequence; the score is: $$\frac{S}{5}\times \sum_{i=1}^{5}[k\le lim_i]$$

The score for the test package is the minimum score among all test cases within that package.

Constraints

For $100\%$ of the data, $1 \le m \le n \le 1000$, and $p$ is a permutation of $1$ to $n$.

For data where a solution exists, the data generation method is: after determining $n$ and $m$, $p$ is randomly generated from the set of permutations that have a solution.

The additional constraints for each test package are as follows:

Test Package ID $n \le$ $m \in$ $lim=$ Score
$1$ $10$ $[1,n]$ $\{50,200,500,2000,10000\}$ $5$
$2$ $\{120,300,1000,3000,10000\}$
$3$ $30$ $\{1000,30000,60000,300000,1000000\}$
$4$ $\{2500,50000,110000,300000,1000000\}$
$5$ $50$ $\{3000,25000,150000,500000,1000000\}$ $15$
$6$ $\{6000,50000,300000,700000,1500000\}$ $5$
$7$ $200$ $\{20000,50000,200000,500000,1000000\}$
$8$ $\{40000,100000,300000,700000,1500000\}$
$9$ $1000$ $[4,5]$ $\{70000,150000,300000,700000,1500000\}$
$10$ $\{100000,200000,400000,800000,1500000\}$
$11$ $[6,8]$ $\{50000,100000,200000,500000,1000000\}$
$12$ $\{60000,120000,250000,500000,1000000\}$
$13$ $[40,60]$ $\{10000,25000,50000,200000,1000000\}$
$14$ $\{12000,30000,60000,200000,1000000\}$
$15$ $[1,n]$ $\{450000,700000,950000,1250000,1500000\}$ $15$
$16$ $\{1000000,1200000,1600000,2200000,2500000\}$ $5$

For odd-numbered test packages, $m$ is guaranteed to be odd; for even-numbered test packages, $m$ is guaranteed to be even.

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.