#P10038. 「FAOI-R2」Program of atom(x) 2027

    ID: 10204 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2024洛谷原创Special JudgeO2优化区间 DP构造

「FAOI-R2」Program of atom(x) 2027

Background

Update on 2025/5/11: We added a visualization tool in the attachments.

Update on 2025/5/26: The visualization tool has been updated.

This is a problem from FAOI in the year 20272027. It is a traditional problem with an SPJ.


After krjt was JC by 160160 people last time, he switched to a "quantum combination lock" and used it to lock his laptop bag. If you cannot open the lock, you cannot take the laptop out of the bag. In theory, once krjt forgets the password, even the person who made the lock cannot open it.

However, this lock is not unbreakable. One day, krjt suddenly became very interested in chemistry. He picked up the lock and heated it over an alcohol lamp, and then found that: In a high-temperature environment, the arrangement of atoms inside the lock (strictly speaking, "ions", same below) becomes unstable, which will cause it to break down.

Problem Description

krjt found the manual of the combination lock:

In the combination lock, there is a chain of length nn (cannot be changed; the specific value of nn can be found on the nameplate). There are nn nodes on the chain. Each node can store at most one atom. Initially, atoms 1,2,,n1,2,\ldots,n are stored in it in some order (the user may adjust it), with one atom per node.

Define the charge of atom ii as i!=1×2×3××ii!=1 \times 2\times 3 \times \ldots \times i.

There is a timer bb (in seconds), with initial value 00.

After the lock is heated, the following events repeat in order until the termination condition is met:

  1. The atoms at both ends of the chain are removed (this does not shorten the chain), and they no longer affect subsequent events.
  2. Check the termination condition:
    • If at this time there are no more than 11 atom left in the chain (it can also be 00), then the termination condition is met, and the lock breaks down (the value of bb will not be increased by 11 at this time).
    • Otherwise, increase the value of bb by 11.
  3. Assign a movement direction to each atom (the assigned direction is temporary, only effective once, and will be reset before the next assignment):
    • Compute the sum of charges of all atoms to its left, and denote the result as xx.
    • Compute the sum of charges of all atoms to its right, and denote the result as yy.
    • If x<yx<y, then the direction is "to the left".
    • If x>yx>y, then the direction is "to the right".
    • It can be proven that xyx \ne y.
  4. All atoms move one edge along their assigned directions to the adjacent node.

In addition, krjt read the value of nn from the nameplate.

krjt defines the time for the lock to break down as the value of bb when it breaks down. Of course, krjt hopes the lock is as secure as possible, so he wants to maximize the breakdown time.

To avoid more people JC krjt again, please answer: how should he arrange the initial order of the nn atoms in the lock?

Input Format

One line with one positive integer nn.

Output Format

One line with nn positive integers, a permutation of 1n1 \sim n, representing the arrangement you design for krjt. Output the IDs of the nn atoms in order from left to right (or from right to left; it can be proven that their breakdown times are the same).

There may be multiple correct answers. Output any one of them.

1
1
2
1 2
3
2 1 3
4
4 2 3 1
5
5 4 1 2 3
6
2 4 5 1 6 3

Hint

Explanation of the samples:

For the 66 samples, the breakdown times are 0,0,0,1,1,20,0,0,1,1,2 seconds.

In fact, by enumeration it can be seen that when n6n \le 6, outputting any permutation of 1n1 \sim n will get AC.

Below is a simulation for sample 66. In the chain description:

  • 00 means the node is empty.
  • ii means the node contains atom ii.
  • (x,y)(x,y) is the computed result.
  1. The initial chain is 245163\color{blue}2-4-5-1-6-3.
  2. Initially, bb is 00.
  3. The atoms at both ends are removed, and the chain becomes 045160\color{blue}0-4-5-1-6-0.
  4. bb increases to 11.
  5. Compute. For the 44 atoms (from left to right), the results are $(\color{red}0\color{black},841),(\color{red}24\color{black},721),(\color{red}144\color{black},720),(145,\color{red}0\color{black})$.
  6. According to the results, the left 33 atoms (4,5,14,5,1) move left, and the rightmost atom (66) moves right, and the chain becomes 451006\color{blue}4-5-1-0-0-6.
  7. The atoms at both ends are removed, and the chain becomes 051000\color{blue}0-5-1-0-0-0.
  8. bb increases to 22.
  9. Compute. For the 22 atoms (from left to right), the results are $(\color{red}0\color{black},1),(120,\color{red}0\color{black})$.
  10. According to the results, the left atom (55) moves left, and the right atom (11) moves right, and the chain becomes 500100\color{blue}5-0-0-1-0-0.
  11. The atoms at both ends are removed, and the chain becomes 000100\color{blue}0-0-0-1-0-0.
  12. At this time, only 11 atom (11) remains in the chain, so the process ends and the lock breaks down.

In summary, the breakdown time for sample 66 is 22 seconds.


This problem has 100100 test points, with n=1,2,,100n=1,2,\ldots,100, 11 point each.

For 100%100\% of the testdata, 1n1001 \le n \le 100.

Input Format

One line with one positive integer nn.

Output Format

One line with nn positive integers, a permutation of 1n1 \sim n, representing the arrangement you design for krjt. Output the IDs of the nn atoms in order from left to right (or from right to left; it can be proven that their breakdown times are the same).

There may be multiple correct answers. Output any one of them.

Hint

Explanation of the samples:

For the 66 samples, the breakdown times are 0,0,0,1,1,20,0,0,1,1,2 seconds.

Actually, by enumeration it can be seen that when n6n \le 6, outputting any permutation of 1n1 \sim n will get AC.

Below is a simulation for sample 66. In the chain description:

  • 00 means the node is empty.
  • ii means the node contains atom ii.
  • (x,y)(x,y) is the computed result.
  1. The initial chain is 245163\color{blue}2-4-5-1-6-3.
  2. Initially, bb is 00.
  3. The atoms at both ends are removed, and the chain becomes 045160\color{blue}0-4-5-1-6-0.
  4. bb increases to 11.
  5. Compute. For the 44 atoms (from left to right), the results are $(\color{red}0\color{black},841),(\color{red}24\color{black},721),(\color{red}144\color{black},720),(145,\color{red}0\color{black})$.
  6. According to the results, the left 33 atoms (4,5,14,5,1) move left, and the rightmost atom (66) moves right, and the chain becomes 451006\color{blue}4-5-1-0-0-6.
  7. The atoms at both ends are removed, and the chain becomes 051000\color{blue}0-5-1-0-0-0.
  8. bb increases to 22.
  9. Compute. For the 22 atoms (from left to right), the results are $(\color{red}0\color{black},1),(120,\color{red}0\color{black})$.
  10. According to the results, the left atom (55) moves left, and the right atom (11) moves right, and the chain becomes 500100\color{blue}5-0-0-1-0-0.
  11. The atoms at both ends are removed, and the chain becomes 000100\color{blue}0-0-0-1-0-0.
  12. At this time, only 11 atom (11) remains in the chain, so the process ends and the lock breaks down.

In summary, the breakdown time for sample 66 is 22 seconds.


This problem has 100100 test points, with n=1,2,,100n=1,2,\ldots,100, 11 point each.

For 100%100\% of the testdata, 1n1001 \le n \le 100.

Translated by ChatGPT 5