Sugoroku
InterviewTime limit2sMemory limit512 MB
Squares 2 to N+1 are each marked 0 or 1; find the smallest die size j such that some sequence of rolls from 1 to j reaches or passes square N+2 without landing on any square marked 1.
- Level
Medium5 of 10
- Topics
- Dynamic programming, BFS, Graph, Greedy
- Solved
- No attempts yet
Problem
JOI found a sugoroku board at his uncle's house. The board is a line of squares. Square 1 is the start and square is the goal. Every other square has either 0 or 1 written on it, and for each () the number written on square is .
The game begins with the piece on the start square. After that, you repeat one action: roll the die and move the piece forward by the number rolled. If the piece stops on a square with 1 written on it, the game is over. If the piece never stops on a square with 1 and it either stops exactly on the goal square or moves past the goal square, the game is cleared.
JOI went to a toy shop to buy a die for the game. The shop sells dice. Die () has faces, with written one per face.
Among the dice for which some sequence of rolls clears the game, JOI buys the one with the fewest faces. Which die should he buy?
Input
The input is given from standard input in the following format.
N
A_1 A_2 ... A_N
Output
Print the number of faces of the die JOI should buy, on one line.
Constraints
- ()