B. Bear and Blocks

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/573/problem/B

Description

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 hi 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.

Input

The first line contains single integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — sizes of towers.

Output

Print the number of operations needed to destroy all towers.

Sample Input

6
2 1 4 6 2 2

Sample Output

3

HINT

题意

每次会消除与外界相互接触的方块,问你得消除多少次,才能把所有方块都消除完

题解

对于每个数,我们统计一下从左边消除得消除多少次,从右边消除得消除多少次

然后O(n)跑一遍就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
//**************************************************************************************int n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll ans=0;
int main()
{n=read();for(int i=1;i<=n;i++)a[i]=read();for(int i=1;i<=n;i++)b[i]=min(b[i-1]+1,a[i]);for(int i=n;i>=1;i--)c[i]=min(c[i+1]+1,a[i]);for(int i=1;i<=n;i++)ans=max(ans,min(b[i],c[i]));cout<<ans<<endl;
}

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) B. Bear and Blocks 水题相关推荐

  1. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  2. Codeforces Round #370 (Div. 2) A. Memory and Crow 水题

    A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...

  3. Codeforces Round #311 (Div. 2) A. Ilya and Diplomas 水题

    A. Ilya and Diplomas Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/ ...

  4. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题

    A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...

  5. Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题

    A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...

  6. Codeforces Round #404 (Div. 2) B. Anton and Classes 水题

    B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...

  7. Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题

    A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...

  8. Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题

    A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...

  9. Codeforces Round #307 (Div. 2) A. GukiZ and Contest 水题

    A. GukiZ and Contest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  10. Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

    B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...

最新文章

  1. 你可能没那么了解 JWT
  2. tensorflow eager调试模式关键导入如下两行便于debug
  3. WPF使用IDataErrorInfo进行数据校验
  4. 5.MySQL Cluster(MySQL集群)
  5. 【效率】推荐几个不错的网站!
  6. 干货|吴恩达Coursera课程教你学习神经网络二!
  7. notnull注解_Hibernate Validator 第19篇:自定义约束-约束注解
  8. 微信小程序引入骨架屏组件
  9. SystemVerilog中根据系统时间产生随机数的函数
  10. redis内存数据的持久化方式
  11. win10安装mvn,安装ojdbc7.jar
  12. 没有 本地计算机策略组,本地组策略编辑器没有mmc
  13. QT应用之透明背景_嵌入式freambuffer_QWS背景淡绿色问题
  14. Python之数据加密与解密及相关操作(hashlib、hmac、random、base64、pycrypto)
  15. 小程序通过摄像头拍摄个人身份证
  16. oracle的insert写法,Oracle中Insert语句的总结
  17. vba 添加outlook 签名_调用Outlook发送邮件-附带签名
  18. web前端期末大作业——开心旅游网站设计与实现(HTML+CSS+JavaScript)
  19. 一种踩内存的定位方法(C++)
  20. 中小型网络系统总体规划与设计方法(一)

热门文章

  1. (转)MapReduce二次排序
  2. DataTable的Select方法
  3. SiteMesh配置下载使用(简单介绍)
  4. Request.Querystring中文乱码问题解决
  5. 130242014039-(2)-体验敏捷开发
  6. 测试评审要点说明(测试计划、用例、报告)
  7. 产品经理第一件事-系统背景研究
  8. [Microsoft][ODBC 驱动程序管理器] 在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配...
  9. MapX从数据库读取数据形成新图层【转载】
  10. IntelliJ IDEA使用技巧(五)——页面乱码和控制台乱码