#K9676. Frog River Crossing
Frog River Crossing
Frog River Crossing
A frog is trying to cross a river by jumping on stones. The stones are arranged in a straight line at specific positions. The frog starts on the first stone at position 0. If the frog makes a jump of length k from a stone, its next jump must be either k-1, k, or k+1 units (expressed in LaTeX: $k-1$, $k$, $k+1$). Given the positions of the stones, determine if the frog can reach the last stone.
Note: The stone positions are given in strictly increasing order. If there is no valid sequence of jumps that allows the frog to land on the last stone, then the answer is False.
inputFormat
The input begins with an integer n
representing the number of stones. The next line contains n
space-separated integers sorted in increasing order that represent the positions of the stones. For example:
8 0 1 3 5 6 8 12 17
indicates there are 8 stones at positions 0, 1, 3, 5, 6, 8, 12, and 17.
outputFormat
Output a single line: True
if the frog can reach the last stone, and False
otherwise.
8
0 1 3 5 6 8 12 17
True