問題一覧 > 通常問題

No.1331 Moving Penguin

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 1.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 116
作問者 : penguinman / テスター : chineristAC
お気に入りにしたユーザー ProblemId : 5203 / 自分の提出
問題文最終更新日: 2021-01-17 18:21:42
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 277 (順位表) の他の問題:

Problem Statement

There are $N$ squares arranged in a horizontal row, called squares $1,\ 2,...N$ from left to right. Square $i$ has an integer $A_i$ written on it.

Penguinman is currently on square $1$ and wants to move to square $N$.

When Penguinman is on square $i$, he can move to a square $j\ (i<j≤N)$ that satisfies at least one of the following conditions.

  • $i≡j\ \bmod\ A_i$.
  • $i+1=j$.

In how many ways can Penguinman move to square $N$? Since the answer can be very large, output it modulo $10^9+7$.

When counting the ways to move, two ways are distinguished only by the set of squares they pass through.

Note

This problem has a tight time limit.

We have confirmed that the intended solution gets AC with PyPy3 (in about $900$ms), but similar code submitted with Python3 got TLE.

We recommend that Python users submit with PyPy3.

Input

$N$
$A_1\ A_2\ ...\ A_N$
  • $2≤N≤10^5$
  • $1≤A_i≤N$
  • All inputs are integers.

Output

Print a newline at the end. Do not forget to take the $\bmod$.

Sample

Sample 1
Input
3
2 1 1
Output
2

There are $2$ ways: moving square $1→$ square $2→$ square $3$, and
moving square $1→$ square $3$.

Sample 2
Input
5
5 5 5 5 5
Output
1

From any square, he can only move to the square $1$ ahead.

Sample 3
Input
10
5 1 9 1 1 3 4 2 1 10
Output
57

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。