#P16795. [蓝桥杯 2026 国 B] 奇偶校验排列
[蓝桥杯 2026 国 B] 奇偶校验排列
Problem Description
A certain checking system needs to use each of the numbers exactly once and arrange them into a sequence of length , . Such a sequence is called a permutation.
The system generates a check string of length based on the parity of the absolute differences between adjacent numbers in the permutation. For each , the -th check character is determined by the following rules:
- If is even, then is .
- If is odd, then is .
Now you are given a target check string of length . You need to construct a permutation such that the generated check string is exactly equal to .
If there are multiple valid permutations, output the lexicographically smallest one. For two different permutations and , if there exists a position such that the first numbers are the same and , then permutation is lexicographically smaller than permutation .
If no such permutation exists, output .
Input Format
The first line contains an integer , representing the number of labels.
The second line contains a string of length , representing the target check string. The string consists only of characters and .
Output Format
If no valid permutation exists, output a single integer on one line.
Otherwise, output integers on one line, representing the lexicographically smallest valid permutation. Adjacent integers should be separated by one space.
5
1010
1 2 4 3 5
6
00000
-1
8
0101101
1 3 2 4 5 6 8 7
Hint
Sample Explanation 1
The adjacent differences of this permutation are, in order:
- , which is odd, corresponding to .
- , which is even, corresponding to .
- , which is odd, corresponding to .
- , which is even, corresponding to .
Therefore, the generated check string is . Among all valid permutations, is lexicographically the smallest.
Sample Explanation 2
Every character of the target check string is , so every adjacent difference must be even, meaning the two numbers must have the same parity. Then all numbers in all positions must have the same parity, but among to there are both odd and even numbers, so there is no solution.
Sample Explanation 3
The check string generated by the output permutation is, in order, , , , , , , , which is the same as the target check string .
Constraints and Notes for Testdata
For of the testdata, .
For of the testdata, .
For all testdata, , and the length of is .
Translated by ChatGPT 5