#P7812. [JRKSJ R2] Dark Forest
[JRKSJ R2] Dark Forest
Background
This is an output-only problem.
Problem Description
You are given a sequence of length . Define the weight of a permutation of as
You may treat this permutation as a cycle, i.e., .
Please construct a permutation of with the weight as large as possible.
Input Format
The first line contains an integer .
The second line contains integers representing the sequence .
Output Format
Output one line with integers representing the permutation.
5
1 4 3 2 5
1 3 5 2 4
Hint
Note that it is a[p[i-1]] a[p[i+1]]. The testdata has some gradation.
Constraints
For of the testdata, .
Sample Explanation
The weight of this permutation is $1\times2\times1\times3+3\times1\times3\times5+5\times3\times5\times4+2\times5\times4\times2+4\times4\times2\times1=463$. It can be proven that this is one of the optimal permutations.
Scoring
This problem uses Special Judge. Each test point has parameters . If the weight of your output is , then on that test point you will get at least points.
In particular, if your output is not a permutation of , you will get points on that test point.
The scoring parameters have been provided in the attachment.
Translated by ChatGPT 5