#P15405. [NOISG 2026 Prelim] 魔术戏法(暂无数据)
[NOISG 2026 Prelim] 魔术戏法(暂无数据)
Problem Description
A new format of cards has been released. The value of each card is a base64 string of length . The character set is: {#, $, 0-9, A-Z, a-z}.
There are cards in total, and each string appears exactly once. The sealed new deck is sorted in lexicographical order from smallest to largest.
Definition: a string is lexicographically greater than if and only if there exists a position such that and .
The shuffle is repeated infinitely many times. Each shuffle is performed as follows:
- Split the deck into two halves: the first half is positions , and the second half is positions (the internal order of each half remains unchanged).
- Starting from the first half, take cards alternately from the two halves. If before shuffling the positions are numbered , then after one shuffle the order becomes $\langle 1, \frac{n}{2} + 1, 2, \frac{n}{2} + 2, \ldots, \frac{n}{2}, n \rangle$.
There are tricks. The -th trick requires that the card with value ends up at the position where the card with value is in the original sealed deck. Find the minimum number of shuffles needed to meet the condition. Output if it is already satisfied initially; output if it can never be satisfied.
Input Format
- The first line contains two integers . .
- The next lines each contain two strings , both of length . All strings use only the 64 characters above.
Output Format
For each trick, output one line with an integer: the number of shuffles needed for the condition to be satisfied for the first time; if it is impossible, output .
1 7
# #
U $
4 3
t D
D t
2 5
$ 2
0
1
-1
3
3
-1
2
3 8
Hd7 CYZ
mZs 1Z8
iYq poa
JlP edh
SyR uxw
aCp n50
I#9 0q8
wRP t1r
2
-1
15
-1
13
-1
-1
-1
Hint
Constraints
Subtasks
| Subtask ID | Properties | Score |
|---|---|---|
| 1 | 20 | |
| 2 | 30 | |
| 3 | No special constraints | 50 |
Translated by ChatGPT 5