問題一覧 > 通常問題

No.1868 Teleporting Cyanmond

レベル : / AI推定難易度 : 700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 160
作問者 : shiomusubi496 / テスター : ぷら kaichou243
お気に入りにしたユーザー ProblemId : 7353 / 自分の提出
問題文最終更新日: 2022-03-11 15:09:24
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 335 (順位表) の他の問題:

Problem Statement

There are $N$ towns $1, 2, \ldots, N$ lined up on a straight line in this order. Cyanmond is currently in town $1$ and wants to travel to town $N$.

Each town other than town $N$ has a teleporter, and from town $i$ one can teleport to any of the towns $i+1, i+2, \ldots, R_i$.

Cyanmond wants to get to town $N$ as quickly as possible. Tell Cyanmond the minimum number of teleports needed to reach town $N$.

(Original idea: Cyanmond)

Input

$N$
$R_1$ $R_2$ $\cdots$ $R_{N-1}$
  • $2 \leq N \leq 10^5$
  • $i < R_i \leq N$ $(1 \leq i \leq N - 1)$
  • All inputs are integers.

Output

Output the minimum number of teleports needed to reach town $N$.

Sample

Sample 1
Input
5
2 4 4 5
Output
3

For example, traveling through towns in the order $1 \to 2 \to 4 \to 5$ is optimal.

Sample 2
Input
8
8 8 8 8 8 8 8
Output
1

It is possible to move directly from town $1$ to town $8$.

Sample 3
Input
20
4 7 7 6 10 9 8 9 13 15 13 16 17 15 18 18 20 20 20
Output
6

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