A8004 | Trees
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
On Bertown's main street $n$ trees are growing, the tree number $i$ has the height of $a_{i}$ meters ( $1<=i<=n$ ). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the $1$ st one and the $n$ -th one) should be equal to each other, the heights of the $2$ -nd and the $(n-1)$ -th tree must also be equal to each other, at that the height of the $2$ -nd tree should be larger than the height of the first tree by $1$ , and so on. In other words, the heights of the trees, standing at equal distance from the edge (of one end of the sequence) must be equal to each other, and with the increasing of the distance from the edge by $1$ the tree height must also increase by $1$ . For example, the sequences "2 3 4 5 5 4 3 2" and "1 2 3 2 1" are beautiful, and '1 3 3 1" and "1 2 3 1" are not.
Changing the height of a tree is a very expensive operation, using advanced technologies invented by Berland scientists. In one operation you can choose any tree and change its height to any number, either increase or decrease. Note that even after the change the height should remain a positive integer, i. e, it can't be less than or equal to zero. Identify the smallest number of changes of the trees' height needed for the sequence of their heights to become beautiful.
Changing the height of a tree is a very expensive operation, using advanced technologies invented by Berland scientists. In one operation you can choose any tree and change its height to any number, either increase or decrease. Note that even after the change the height should remain a positive integer, i. e, it can't be less than or equal to zero. Identify the smallest number of changes of the trees' height needed for the sequence of their heights to become beautiful.
输入格式
The first line contains integer $n$ ( $1<=n<=10^{5}$ ) which is the number of trees. The second line contains integers $a_{i}$ ( $1<=a_{i}<=10^{5}$ ) which are the heights of the trees.
输出格式
Print a single number which is the minimal number of trees whose heights will have to be changed for the sequence to become beautiful.
输入输出样例
输入 #1
3 2 2 2
输出 #1
1
输入 #2
4 1 2 2 1
输出 #2
0
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted