🔗 문제 링크
백준 25706번 - 자전거 묘기
📝 풀이

public class 자전거묘미_25706 {
public static void run(int n, int[] heights) {
int [] result = new int[n];
for(int i = n-1; i >= 0; i--) {
int step = i + heights[i] + 1;
if(step >= n) {
result[i] = 1;
}
else {
result[i] = result[step] + 1;
}
}
for(int num: result) {
System.out.print(num + " ");
}
}
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int[] heights = new int[n];
for(int i = 0; i < n; i++) {
heights[i] = Integer.parseInt(st.nextToken());
}
run(n, heights);
}