cswork / OA打开练习工作台

UberOA #44

Jump Game with Prime-Step Rule

估计中等可在线判题

考点(AI 标注)动规入门位运算

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.

输入格式

The first line contains n, and the second line contains n maximum jump lengths; 1≤n≤200000, 0≤nums[i]≤10⁹.

输出格式

Output one integer, the answer.

样例 1

输入:

5
2 3 1 1 0

输出:

0

样例 2

输入:

4
1 1 1 1

输出:

0

样例 3

输入:

5
2 0 2 0 0

输出:

1

样例说明

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.