#P7962. [NOIP2021] 方差

    ID: 9047 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2021NOIP 提高组O2优化模拟退火动态规划优化

[NOIP2021] 方差

Problem Description

Given a non-strictly increasing sequence of positive integers of length nn: 1a1a2an1 \le a_1 \le a_2 \le \cdots \le a_n. In each operation, you may choose any positive integer 1<i<n1 < i < n and change aia_i to ai1+ai+1aia_{i - 1} + a_{i + 1} - a_i. After performing some operations, find the minimum possible variance of the sequence. Output the result of the minimum variance multiplied by n2n^2.

The variance is defined as the average of the squared differences between each number and the mean. More formally, the variance is $D = \frac{1}{n} \sum_{i = 1}^{n} {(a_i - \bar a)}^2$, where aˉ=1ni=1nai\bar a = \frac{1}{n} \sum_{i = 1}^{n} a_i.

Input Format

The first line contains a positive integer nn, and it is guaranteed that n104n \le {10}^4.

The second line contains nn positive integers, where the ii-th number is aia_i. The testdata guarantees that 1a1a2an1 \le a_1 \le a_2 \le \cdots \le a_n.

Output Format

Output a single line containing a non-negative integer, which is the minimum variance you can obtain multiplied by n2n^2.

4
1 2 4 6

52

见附件中的 variance/variance2.in
见附件中的 variance/variance2.ans
见附件中的 variance/variance3.in
见附件中的 variance/variance3.ans
见附件中的 variance/variance4.in
见附件中的 variance/variance4.ans

Hint

Sample Explanation #1

For (a1,a2,a3,a4)=(1,2,4,6)(a_1, a_2, a_3, a_4) = (1, 2, 4, 6), after the first operation, the possible sequence is (1,3,4,6)(1, 3, 4, 6). After the second operation, the new sequence is (1,3,5,6)(1, 3, 5, 6). After that, no new sequence can be obtained.

For (a1,a2,a3,a4)=(1,2,4,6)(a_1, a_2, a_3, a_4) = (1, 2, 4, 6), the mean is 134\frac{13}{4}, and the variance is $\frac{1}{4}({(1 - \frac{13}{4})}^2 + {(2 - \frac{13}{4})}^2 + {(4 - \frac{13}{4})}^2 + {(6 - \frac{13}{4})}^2) = \frac{59}{16}$.

For (a1,a2,a3,a4)=(1,3,4,6)(a_1, a_2, a_3, a_4) = (1, 3, 4, 6), the mean is 72\frac{7}{2}, and the variance is $\frac{1}{4} ({(1 - \frac{7}{2})}^2 + {(3 - \frac{7}{2})}^2 + {(4 - \frac{7}{2})}^2 + {(6 - \frac{7}{2})}^2) = \frac{13}{4}$.

For (a1,a2,a3,a4)=(1,3,5,6)(a_1, a_2, a_3, a_4) = (1, 3, 5, 6), the mean is 154\frac{15}{4}, and the variance is $\frac{1}{4} ({(1 - \frac{15}{4})}^2 + {(3 - \frac{15}{4})}^2 + {(5 - \frac{15}{4})}^2 + {(6 - \frac{15}{4})}^2) = \frac{59}{16}$.

Constraints

Test Point ID nn \le aia_i \le
131 \sim 3 44 1010
454 \sim 5 1010 4040
686 \sim 8 1515 2020
9129 \sim 12 2020 300300
131513 \sim 15 5050 7070
161816 \sim 18 100100 4040
192219 \sim 22 400400 600600
232523 \sim 25 104{10}^4 5050

For all testdata, it is guaranteed that 1n1041 \le n \le {10}^4 and 1ai6001 \le a_i \le 600.

Translated by ChatGPT 5