QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100

#8736. Permutation

统计

Mo loves finding patterns in numbers. For example, in the sequence $1, 4, 7, (\dots)$, the difference between adjacent numbers is $3$, so the number in the parentheses should be $10$. In another example, $3, 6, 12, (\dots)$, each number is twice the previous one, so the number in the parentheses should be $24$.

Because she has been playing such games for years, Mo has grown tired of arithmetic and geometric progressions. When she sees the sequence $1, 2, \dots, n$, she wants to change its order as little as possible such that there is no subsequence with a common difference of $A$ or a common ratio of $B$.

Specifically, given integers $n, A, B$, find a permutation $P = (P_1, P_2, \dots, P_n)$ of $1$ to $n$ such that for all $i, j \in \{1, 2, \dots, n\}$, if $i < j$ and $P_i < P_j$, then $P_j \neq P_i + A$ and $P_j \neq P_i \times B$.

The degree $S$ to which the permutation $P$ preserves the original order is defined as: $$S = \sum_{1 \le i < j \le n, P_i < P_j} (P_j - P_i)$$

Your task is to maximize the value of $S$ while satisfying the aforementioned requirements.

Input

The first line contains three positive integers $n, A, B$, as described above. Numbers are separated by a single space.

Output

The first line contains $n$ integers representing the permutation $P$ you found, with numbers separated by spaces.

Examples

Input 1

4 3 2

Output 1

4 2 1 3

Note

For this permutation, $S = 3$, which is the maximum possible value for $n = 4, A = 3, B = 2$.

Subtasks

Each test case is scored individually.

For each test case, if your output is invalid (e.g., incorrect file format, the solution does not meet the requirements), you will receive $0$ points. Otherwise, let $your\_ans$ be the $S$ value of your permutation and $our\_ans$ be the $S$ value of the permutation provided by us. Your score for the test case is calculated as follows:

If $your\_ans \ge our\_ans$, you receive $10$ points. Otherwise, your score is: $\max \left\{ \lfloor 10 \times e^{\frac{your\_ans}{our\_ans} - 2} \rfloor, 1 \right\}$.

Constraints

There are a total of $10$ test cases. The data ranges are as follows:

Test Case $n$ $A$ $B$
1 $\le 30$ $\le n$ $\le n$
2 $\le 60$ $A$ is not a multiple of $B$ $\ge 4$
3 $\le 70$ $\ge 5$
4 $\le 80$ $\ge 6$
5 $\le 90$ $\ge 7$
6 $\le 90$ $\le n$ $= 1$
7 $\le 90$ $\le 5$ $\le n$
8 $\le 90$ $\le 5$ $\le n$
9 $= 60$ $= 21$ $= 3$
10 $= 90$ $= 18$ $= 2$

In all input data, $A$ and $B$ are positive integers not exceeding $n$.

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.