CF1696E.Placing Jinas

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

We say an infinite sequence a0,a1,a2,a_{0}, a_{1}, a_2, \ldots is non-increasing if and only if for all i0i\ge 0 , aiai+1a_i \ge a_{i+1} .

There is an infinite right and down grid. The upper-left cell has coordinates (0,0)(0,0) . Rows are numbered 00 to infinity from top to bottom, columns are numbered from 00 to infinity from left to right.

There is also a non-increasing infinite sequence a0,a1,a2,a_{0}, a_{1}, a_2, \ldots . You are given a0a_0 , a1a_1 , \ldots , ana_n ; for all i>ni>n , ai=0a_i=0 . For every pair of xx , yy , the cell with coordinates (x,y)(x,y) (which is located at the intersection of xx -th row and yy -th column) is white if y<axy<a_x and black otherwise.

Initially there is one doll named Jina on (0,0)(0,0) . You can do the following operation.

  • Select one doll on (x,y)(x,y) . Remove it and place a doll on (x,y+1)(x,y+1) and place a doll on (x+1,y)(x+1,y) .

Note that multiple dolls can be present at a cell at the same time; in one operation, you remove only one. Your goal is to make all white cells contain 00 dolls.

What's the minimum number of operations needed to achieve the goal? Print the answer modulo 109+710^9+7 .

输入格式

The first line of input contains one integer nn ( 1n21051\le n\le 2\cdot 10^5 ).

The second line of input contains n+1n+1 integers a0,a1,,ana_0,a_1,\ldots,a_n ( 0ai21050\le a_i\le 2\cdot 10^5 ).

It is guaranteed that the sequence aa is non-increasing.

输出格式

Print one integer — the answer to the problem, modulo 109+710^9+7 .

输入输出样例

  • 输入#1

    2
    2 2 0

    输出#1

    5
  • 输入#2

    10
    12 11 8 8 6 6 6 5 3 2 1

    输出#2

    2596

说明/提示

Consider the first example. In the given grid, cells (0,0),(0,1),(1,0),(1,1)(0,0),(0,1),(1,0),(1,1) are white, and all other cells are black. Let us use triples to describe the grid: triple (x,y,z)(x,y,z) means that there are zz dolls placed on cell (x,y)(x,y) . Initially the state of the grid is (0,0,1)(0,0,1) .

One of the optimal sequence of operations is as follows:

  • Do the operation with (0,0)(0,0) . Now the state of the grid is (1,0,1),(0,1,1)(1,0,1),(0,1,1) .
  • Do the operation with (0,1)(0,1) . Now the state of the grid is (1,0,1),(1,1,1),(0,2,1)(1,0,1),(1,1,1),(0,2,1) .
  • Do the operation with (1,0)(1,0) . Now the state of the grid is (1,1,2),(0,2,1),(2,0,1)(1,1,2),(0,2,1),(2,0,1) .
  • Do the operation with (1,1)(1,1) . Now the state of the grid is (1,1,1),(0,2,1),(2,0,1),(1,2,1),(2,1,1)(1,1,1),(0,2,1),(2,0,1),(1,2,1),(2,1,1) .
  • Do the operation with (1,1)(1,1) . Now the state of the grid is (0,2,1),(2,0,1),(1,2,2),(2,1,2)(0,2,1),(2,0,1),(1,2,2),(2,1,2) .

Now all white cells contain 00 dolls, so we have achieved the goal with 55 operations.

首页