-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11060.cpp
More file actions
44 lines (31 loc) · 846 Bytes
/
11060.cpp
File metadata and controls
44 lines (31 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include <string>
using namespace std;
typedef pair<int, int>P;
int arr[1001];
int visited[1001];
queue <P> q;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int N; cin >> N;
for (int i = 0; i < N; i++)cin >> arr[i];
q.push(P(0, 0));
visited[0] = 1;
while (!q.empty()) {
P curr = q.front(); q.pop();
if (curr.first == N - 1) {
cout << curr.second;
return 0;
}
for (int i = 1; i <= arr[curr.first]; i++) {
if (visited[curr.first + i])continue;
visited[curr.first + i] = 1;
q.push(P(curr.first + i, curr.second + 1));
}
}
cout << "-1";
}