#P11311. 漫长的小纸带
漫长的小纸带
Description
After years of brute force training, Little has mastered the art. During SPSC 2077, he was delighted to find that the second problem, “The Long Paper Tape,” was a challenging one - perfect for a brute force specialist like him.
This is a multiple test case problem with test cases in one test point. The size of the i-th test case is . He wrote a brute force program where, for a continuous segment of data, the time needed to solve that segment is the square of the number of different values in that segment. Formally, for a continuous segment from the l-th to the r-th test case, let , the program needs time to solve them together.
Now, given and the sizes of test cases, find a way to divide these cases into several segments so that the total time consumed by the program is minimized.
Input Format
The first line contains an integer .
The next line contains integers , representing the size of each test case.
Output Format
Output one number representing the minimum total time consumption.
5
1 2 3 4 5
5
6
1 2 2 1 2 3
5
9
1 2 1 4 1 2 1 1 2
8
21
1 2 1 2 1 2 1 2 1 2 3 4 5 6 7 1 2 1 2 1 2
13
Hint
「Sample 3 Explanation」
The segments are:
- First segment , cost = ;
- Second segment , cost = ;
- Third segment , cost = ;
- Fourth segment , cost = ;
- Fifth segment , cost = ;
Therefore, the total time consumption is .
「Data Constraints」
For 100% of test cases:,。
| Subtask ID | Special Property | pts | |
|---|---|---|---|
| - | |||
| - | A | ||
| B | |||
| - |
Special Property A: All are randomly generated with uniform distribution in range , and this subtask has only one test point.
Special Property B: .
京公网安备 11011102002149号