#P8787. [蓝桥杯 2022 省 B] 砍竹子

[蓝桥杯 2022 省 B] 砍竹子

Problem Description

On this day, Xiaoming is cutting bamboo. In front of him there are nn bamboo plants in a row. At the beginning, the height of the ii-th bamboo plant is hih_i.

He feels that cutting them one by one is too slow, so he decides to use magic to cut the bamboo. The magic can be used on a consecutive segment of bamboo plants that all have the same height. Suppose the height of this segment is HH. Then using the magic once can change the heights of all bamboo plants in this segment to $\left\lfloor\sqrt{\left\lfloor\frac{H}{2}\right\rfloor+1}\right\rfloor$, where x\lfloor x\rfloor means rounding xx down.

Xiaoming wants to know the minimum number of times he needs to use magic to make the heights of all bamboo plants become 11.

Input Format

The first line contains a positive integer nn, representing the number of bamboo plants.

The second line contains nn positive integers hih_i separated by spaces, representing the height of each bamboo plant.

Output Format

Output one integer, the answer.

6
2 1 4 2 6 7
5

Hint

Sample Explanation.

One possible plan:

$214267\rightarrow 214262\rightarrow 214222\rightarrow 211222\rightarrow 111222\rightarrow 111111$

A total of 5 steps are needed.

Constraints.

For 20%20\% of the testdata, it is guaranteed that n1000n \leq 1000 and hi106h_i \leq 10^6.

For 100%100\% of the testdata, it is guaranteed that n2×105n \leq 2 \times 10^5 and hi1018h_i \leq 10^{18}.

Lanqiao Cup 2022 Provincial Contest B Group, Problem J.

Translated by ChatGPT 5