302939: CF573B. Bear and Blocks

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Bear and Blocks

题意翻译

题目描述 zpy又发明了一个小游戏,炸方块。 有n列方块,每列方块分别有hi个方块构成,也就是高度为hi。zpy定义边缘方块是这样的:如果一个方块上下左右都有接触到其他方块或地面,就算内部方块,否则就是边缘方块。这个游戏每次可以将当前的边缘方块全部炸掉,这些炸掉的方块就会消失,余下剩余的方块,这个时候,剩余方块里不少方块变成边缘方块,又可以被炸掉了。 zpy现在想知道的是,给定初始方块情况,炸多少次方块会全部消失? 样例的情况如下图: 炸3次方块全部炸光了。 输入 第一行输入n 第二行输入n个整数hi 输出 输出次数 样例输入 6 2 1 4 6 2 2 样例输出 3 提示 【样例说明】 7 3 3 3 1 3 3 3 输出:2 【数据规模和约定】 1<=n<=10^5 1<=hi<=10^9

题目描述

Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built $ n $ towers in a row. The $ i $ -th tower is made of $ h_{i} $ identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time. Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.

输入输出格式

输入格式


The first line contains single integer $ n $ ( $ 1<=n<=10^{5} $ ). The second line contains $ n $ space-separated integers $ h_{1},h_{2},...,h_{n} $ ( $ 1<=h_{i}<=10^{9}) $ — sizes of towers.

输出格式


Print the number of operations needed to destroy all towers.

输入输出样例

输入样例 #1

6
2 1 4 6 2 2

输出样例 #1

3

输入样例 #2

7
3 3 3 1 3 3 3

输出样例 #2

2

说明

The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF573B/256df13c1ef1192f2e98a72ff5ba9bb98f4ceade.png) After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.

Input

题意翻译

题目描述 zpy又发明了一个小游戏,炸方块。 有n列方块,每列方块分别有hi个方块构成,也就是高度为hi。zpy定义边缘方块是这样的:如果一个方块上下左右都有接触到其他方块或地面,就算内部方块,否则就是边缘方块。这个游戏每次可以将当前的边缘方块全部炸掉,这些炸掉的方块就会消失,余下剩余的方块,这个时候,剩余方块里不少方块变成边缘方块,又可以被炸掉了。 zpy现在想知道的是,给定初始方块情况,炸多少次方块会全部消失? 样例的情况如下图: 炸3次方块全部炸光了。 输入 第一行输入n 第二行输入n个整数hi 输出 输出次数 样例输入 6 2 1 4 6 2 2 样例输出 3 提示 【样例说明】 7 3 3 3 1 3 3 3 输出:2 【数据规模和约定】 1<=n<=10^5 1<=hi<=10^9

加入题单

上一题 下一题 算法标签: