A10040 | Bear and Blocks
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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.
 After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.
 After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted