#P7812. [JRKSJ R2] Dark Forest

    ID: 8252 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2021洛谷原创提交答案Special Judge模拟退火遗传算法随机化

[JRKSJ R2] Dark Forest

Background

This is an output-only problem.

Problem Description

You are given a sequence aa of length nn. Define the weight of a permutation pp of 1n1 \dots n as

i=1npiapi1apiapi+1\sum_{i=1}^n p_i a_{p_{i-1}} a_{p_i}a_{p_{i+1}}

You may treat this permutation as a cycle, i.e., p0=pn,pn+1=p1p_{0}=p_n, p_{n+1}=p_1.

Please construct a permutation of 1n1 \dots n with the weight as large as possible.

Input Format

The first line contains an integer nn.

The second line contains nn integers representing the sequence aa.

Output Format

Output one line with nn 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 100%100\% of the testdata, 1n,ai1031 \le n, a_i \le 10^3.

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 1010 parameters v1,v2,v10v_1, v_2, \dots v_{10}. If the weight of your output is VviV \ge v_i, then on that test point you will get at least ii points.

In particular, if your output is not a permutation of 1n1 \dots n, you will get 00 points on that test point.

The scoring parameters have been provided in the attachment.

Translated by ChatGPT 5