UberOA #44
Jump Game with Prime-Step Rule
Estimated MediumJudge-ready
Topics (AI-labelled)DP BasicsBits & Math
Starting from index 0, you may only jump to a larger index j, where j−i must be prime and must not exceed nums[i]. Determine whether you can reach the last index. In the original example [2,3,1,1,0], you cannot jump 2 steps from index 2, so by the statement the output should be 0.
This site has made the standard input and output explicit.
Input
The first line contains n, and the second line contains n maximum jump lengths; 1≤n≤200000, 0≤nums[i]≤10⁹.
Output
Output one integer, the answer.
Example 1
Input:
5
2 3 1 1 0
Output:
0
Example 2
Input:
4
1 1 1 1
Output:
0
Example 3
Input:
5
2 0 2 0 0
Output:
1
Example notes
Example 1: you can only go from 0 to 2, and nums[2]=1 cannot continue, so the correct answer is 0. Example 2: 1 is not prime, so no move is possible; output 0. Example 3: 0→2→4 uses two valid steps of 2, so output 1.
Editorial
Loading solution…