forked from SSAFY-5959-STUDY/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boj_11060.java
59 lines (52 loc) · 1.18 KB
/
boj_11060.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cocodingding;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class boj_11060 {
static int[]input;
static Queue<Integer>q;
static boolean[] chk;
static int n, cnt;
static int[]len;
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(br.readLine());
q=new ArrayDeque<>();
input=new int[n];
chk=new boolean[n];
len=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) {
input[i]=Integer.parseInt(st.nextToken());
}
cnt=bfs();
System.out.println(cnt);
}
public static int bfs() {
chk[0]=true;
cnt= 0;
q.offer(0);
while(!q.isEmpty()) {
int size=q.size();
while(--size>=0) {
int now=q.poll();
if(now==input.length-1) {
return cnt;
}
for(int i=now+1;i<=input[now]+now && i<n; i++) {
if(chk[i]==false) {
chk[i]=true;
q.offer(i);
}
}
}
cnt++;
}
return -1;
}
}