CF58C.Trees

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 1st 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.

在 Bertown 的主街上生长着 nn 棵树,其中第 ii 棵树的高度为 aia_i 米(1≤i≤n1 \le i \le n)。为迎接贝尔兰总统的到来,人们决定对这些树进行改造,使其高度构成一个“优美的序列”。所谓优美序列,是指:位于序列两端的树(即第 11 棵与第 nn 棵)高度必须相等;第 22 棵与第 n−1n-1 棵树的高度也必须相等,且该高度应比第 11 棵树高 11;依此类推。换言之,所有与某一端点距离相等的树,其高度必须相同;且当该距离每增加 11,对应树的高度也必须恰好增加 11。例如,序列 2 3 4 5 5 4 3 2 和 1 2 3 2 1 是优美的,而 1 3 3 1 和 1 2 3 1 则不是。

改变一棵树的高度是一项极其昂贵的操作,需借助贝尔兰科学家发明的先进技术。每次操作中,你可以任选一棵树,并将其高度修改为任意正整数(可增大或减小)。注意:修改后的高度仍必须为正整数,即不能小于或等于零。请确定使树高序列变为优美序列所需的最少修改次数。

输入格式

The first line contains integer n (1 ≤ n ≤ 105) which is the number of trees. The second line contains integers a__i (1 ≤ a__i ≤ 105) which are the heights of the trees.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示树的数量。第二行包含整数 aia_i(1≤ai≤1051 \leq a_i \leq 10^5),表示每棵树的高度。

输出格式

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

输入解题思路,AI测评打分。不知道怎么写?

首页