CF750D.New Year and Fireworks

普及+/提高

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on.

Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion _t_1, _t_2, ..., t__n. Once Limak launches the firework in some cell, the firework starts moving upward. After covering _t_1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t_2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2_n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time — it is allowed and such parts do not crash.

Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells?

迎接新年的传统之一是向天空发射烟花。通常,一枚发射的烟花会先垂直向上飞行一段时间,然后爆炸,分裂成若干朝不同方向飞行的部分。有时,这些部分在经过一段时间后也会再次爆炸,分裂成更多部分,如此反复。

生活在无限网格中的 Limak 拥有一枚烟花。该烟花的行为由递归深度 nn 和每一层递归的持续时间 t1, t2, …, tnt_1,\,t_2,\,\dots,\,t_n 描述。一旦 Limak 在某个格子中发射烟花,烟花便开始垂直向上运动。在经过 t1t_1 个格子(包含起始格子)后,它爆炸并分裂成两个部分,每个部分的运动方向均相对于原方向偏转 45∘45^\circ(参见下方图示以明确方向)。因此,一个部分朝左上方运动,另一个部分朝右上方运动。每个部分在经过 t2t_2 个格子后再次爆炸,同样分裂为两个部分,其运动方向再次相对于当前方向偏转 45∘45^\circ。该过程持续进行,直至第 nn 层递归:此时所有 2n−12^{n-1} 个现存部分同时爆炸并消失,不再产生新的部分。在经过若干层递归后,某些部分可能在同一时刻位于同一格子中——这是被允许的,且这些部分不会发生碰撞。

在发射烟花前,Limak 必须确保没有任何人站在烟花至少经过一次的格子中。你能计算出这类格子的总数吗?

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 30) — the total depth of the recursion.

The second line contains n integers _t_1, t_2, ..., t__n (1 ≤ t__i ≤ 5). On the i-th level each of 2_i - 1 parts will cover t__i cells before exploding.

输入的第一行包含一个整数 nn(1≤n≤301 \leq n \leq 30)—— 递归的总深度。

第二行包含 nn 个整数 t1, t2, ..., tnt_1,\,t_2,\,...,\,t_n(1≤ti≤51 \leq t_i \leq 5)。在第 ii 层,每个 2i−12^{i-1} 个部分在爆炸前将覆盖 tit_i 个格子。

输出格式

Print one integer, denoting the number of cells which will be visited at least once by any part of the firework.

输出一个整数,表示至少被烟花的某一部分访问过一次的格子数量。

输入输出样例

  • 输入#1

    4
    4 2 2 3

    输出#1

    39
  • 输入#2

    6
    1 1 1 1 1 3

    输出#2

    85
  • 输入#3

    1
    3

    输出#3

    3

说明/提示

For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered _t_1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39.

For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level.

对于第一个样例,下方的图示展示了每次递归层级后的情形。Limak 从最底部的红色格子发射了烟花。它覆盖了 t1=4t_1 = 4 个格子(标为红色),随后爆炸并分裂为两部分(其后续运动路径标为绿色)。所有爆炸位置均用字符 'X' 标记。在最后一张图中,共有 4 个红色格子、4 个绿色格子、8 个橙色格子和 23 个粉色格子。因此,被访问过的格子总数为 4+4+8+23=394 + 4 + 8 + 23 = 39。

对于第二个样例,下方的图示展示了第 4、第 5 和第 6 层级后的情形。中间的图示标出了将在下一层级中移动的所有部分的方向。

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

首页