#P14502. [NCPC 2025] Hidden Permutation
[NCPC 2025] Hidden Permutation
题目描述
When a fixed shuffle is applied to a deck of cards repeatedly, the deck will eventually return to its original order. The number of times the shuffle must be applied before this happens is called the of the deck for that shuffle. In the present task, we consider the inverse question: rather than starting with a shuffle and finding its period, you are told, for each possible period, how many decks of cards have that period. Your task is to construct any shuffle consistent with this information.
Formally, there is a hidden permutation , where is a given positive integer. A permutation is a list of numbers where each number from to occurs exactly once. Let be a binary string. We say that ( applied to ) is the new binary string , and the of is the smallest positive integer such that
$$\underbrace{f(f(\cdots f(x)\cdots))}_{p\ \text{times}} = x.$$It can be proven that for any permutation and any binary string of the same length, the period of exists. In other words, if you apply to enough times, you eventually get back .
You are given the number , and for each possible period you are given the number of binary strings (out of all possible binary strings) that have period . Your task is to find any permutation that corresponds to the given information, or conclude that there is no such permutation.
输入格式
The input consists of:
- One line with integers , (, ), the length of the permutation and the number of possible periods.
- One line with integers (). These are all the possible periods that binary strings of length can have, with respect to the hidden permutation. The numbers are all distinct, and are sorted in increasing order.
- One line with integers (). This means that there are binary strings with period .
Note that the numbers can be quite large!
输出格式
If there is no permutation that corresponds to the given information, print .
Otherwise, print one line with integers , the permutation that you chose. Recall that the permutation should contain every integer from to exactly once. If there are multiple solutions, you can print any one of them.
7 6
1 2 3 4 6 12
4 4 12 24 12 72
2 3 1 5 6 7 4
91 4
1 7 13 91
2 126 8190 2475880078570760549798240131
impossible
2 1
1
4
1 2
提示
In the second sample, the input almost corresponds to the permutation . The only error is that the last digit in the last number of the input should be instead of .
In the third sample, all binary strings have period , which means that the identity permutation is a valid answer.
京公网安备 11011102002149号