#P7605. [THUPC 2021] 小 E 爱消除
[THUPC 2021] 小 E 爱消除
Description
There are colored balls stuffed in a pipe. All balls have the same diameter. From one end to the other, their colors are .
Little E has an empty cup. The diameter of the cup opening is just slightly larger than the diameter of a ball, so Little E can put balls into the cup, but only one at a time, and the balls can only be stacked vertically in the cup. Any two adjacent balls of the same color in the cup will disappear together.
Because of the special structure of the pipe, each time Little E can only choose one end of the pipe, take out the outermost ball, and then immediately put it into the cup.
After all balls in the pipe have been taken out, ask for the minimum number of balls that can remain in the cup, and under this condition, the minimum required cup capacity.
Input Format
The first line contains a positive integer .
The second line contains positive integers, where the -th one represents .
Output Format
Output one line containing two non-negative integers. The first number is the minimum possible number of balls remaining in the cup. The second number is the minimum number of balls the cup must be able to hold under this condition.
12
3 5 1 4 9 3 3 5 1 4 9 3
0 5
Hint
[Sample Explanation]
One optimal plan is as follows:
First, put the at both ends into the cup to eliminate them.
Then put the left-end balls into the cup in order. At this time there are balls in the cup.
Then put the right-end balls into the cup in order. Each time you put one in, it will eliminate with another ball in the cup. Before the elimination after putting in , the cup contains , so the cup needs to be able to hold balls.
Next put the left-end balls into the cup. At this time there are balls in the cup.
Finally put the right-end balls into the cup in order. Now the cup is empty.
The picture can be found in the attached file Sampledescription.pptx.
[Constraints]
It is guaranteed that , .
[Source]
From the 2021 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2021).
Resources such as the editorial can be found at https://github.com/yylidiw/thupc_1/tree/master.
Translated by ChatGPT 5
京公网安备 11011102002149号