A9695 | New Year Transportation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
New Year is coming in Line World! In this world, there are $n$ cells numbered by integers from $1$ to $n$ , as a $1×n$ board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of $n-1$ positive integers $a_{1},a_{2},...,a_{n-1}$ . For every integer $i$ where $1<=i<=n-1$ the condition $1<=a_{i}<=n-i$ holds. Next, he made $n-1$ portals, numbered by integers from 1 to $n-1$ . The $i$ -th ( $1<=i<=n-1$ ) portal connects cell $i$ and cell $(i+a_{i})$ , and one can travel from cell $i$ to cell $(i+a_{i})$ using the $i$ -th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell $(i+a_{i})$ to cell $i$ using the $i$ -th portal. It is easy to see that because of condition $1<=a_{i}<=n-i$ one can't leave the Line World using portals.
Currently, I am standing at cell $1$ , and I want to go to cell $t$ . However, I don't know whether it is possible to go there. Please determine whether I can go to cell $t$ by only using the construted transportation system.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of $n-1$ positive integers $a_{1},a_{2},...,a_{n-1}$ . For every integer $i$ where $1<=i<=n-1$ the condition $1<=a_{i}<=n-i$ holds. Next, he made $n-1$ portals, numbered by integers from 1 to $n-1$ . The $i$ -th ( $1<=i<=n-1$ ) portal connects cell $i$ and cell $(i+a_{i})$ , and one can travel from cell $i$ to cell $(i+a_{i})$ using the $i$ -th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell $(i+a_{i})$ to cell $i$ using the $i$ -th portal. It is easy to see that because of condition $1<=a_{i}<=n-i$ one can't leave the Line World using portals.
Currently, I am standing at cell $1$ , and I want to go to cell $t$ . However, I don't know whether it is possible to go there. Please determine whether I can go to cell $t$ by only using the construted transportation system.
输入格式
The first line contains two space-separated integers $n$ ( $3<=n<=3×10^{4}$ ) and $t$ ( $2<=t<=n$ ) — the number of cells, and the index of the cell which I want to go to.
The second line contains $n-1$ space-separated integers $a_{1},a_{2},...,a_{n-1}$ ( $1<=a_{i}<=n-i$ ). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
The second line contains $n-1$ space-separated integers $a_{1},a_{2},...,a_{n-1}$ ( $1<=a_{i}<=n-i$ ). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
输出格式
If I can go to cell $t$ using the transportation system, print "YES". Otherwise, print "NO".
输入输出样例
输入 #1
8 4 1 2 1 2 1 2 1
输出 #1
YES
输入 #2
8 5 1 2 1 2 1 1 1
输出 #2
NO
In the first sample, the visited cells are: $1,2,4$ ; so we can successfully visit the cell $4$ .
In the second sample, the possible cells to visit are: $1,2,4,6,7,8$ ; so we can't visit the cell $5$ , which we want to visit.
In the second sample, the possible cells to visit are: $1,2,4,6,7,8$ ; so we can't visit the cell $5$ , which we want to visit.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted