#P15345. [TOIP 2025] 連序
[TOIP 2025] 連序
Problem Description
The binary representation of a non-negative integer can be viewed as a string, with the left side being the most significant bit and the right side being the least significant bit. If it has at most consecutive bits equal to , then the number’s “consecutive order” is defined as . Given non-negative integers, sort them in increasing order of their “consecutive order”. If two numbers have the same consecutive order, output the one with the smaller value first.
For example, the binary representations of , , and are , , and , respectively. Their consecutive orders are , , and . Since and have the same consecutive order but , the output should be, in order, , , .
Input Format
$$\begin{aligned} &n \\ &a_1 \; a_2 \; a_3 \; \cdots \; a_n \end{aligned}$$- is the number of integers to be sorted.
- is the -th integer to be sorted.
Output Format
$$\begin{aligned} &s_1 \; s_2 \; s_3 \; \cdots \; s_n \end{aligned}$$- is the -th integer after sorting according to the requirements.
3
7 12 27
12 27 7
5
1 2 3 4 5
1 2 4 5 3
Hint
Constraints
- .
- .
- All input numbers are integers.
Scoring
This problem has four subtasks with the following constraints. Each subtask may contain one or more testdata files. You will get the score for a subtask only if you answer all testdata files in that subtask correctly.
| Subtask | Score | Additional Input Constraints |
|---|---|---|
| 1 | 22 | 。 |
| 2 | 。 | |
| 3 | 26 | 。 |
| 4 | 30 | No additional constraints. |
Translated by ChatGPT 5