| 比赛 | 
    NNOI2024 | 
    评测结果 | 
    AAAAAAAAAA | 
    | 题目名称 | 
    奇怪的电梯 | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    djyqjy | 
    运行时间 | 
    0.032 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    3.52 MiB  | 
    | 提交时间 | 
    2024-12-28 14:08:43 | 
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int f=1,num=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') num=num*10+c-'0',c=getchar();
	return num*f;
}
const int N=210;
int n,a,b;
int k[N];
queue<int> q;
int t[N];
int x;
int main()
{
	freopen("lift.in","r",stdin);
	freopen("lift.out","w",stdout);
	n=read();a=read();b=read();
	for(int i=1;i<=n;i++) k[i]=read();
	t[a]=1;q.push(a);
	while(!q.empty())
	{
		x=q.front();q.pop();
		if(x+k[x]<=n&&!t[x+k[x]]) q.push(x+k[x]),t[x+k[x]]=t[x]+1;
		if(x-k[x]>=1&&!t[x-k[x]]) q.push(x-k[x]),t[x-k[x]]=t[x]+1;
	}
	if(!t[b]) printf("-1");
	else printf("%d",t[b]-1);
	return 0;
}