[BOJ] 11060 점프 점프

Time Lapse :8min 2sec

11060.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <queue>
using namespace std;
int main(){
bool visit[1001] = {false, };
int jump[1001], N, i, j, c, size, time = 0;
queue<int> q;
scanf("%d",&N);
for(i = 1; i <= N; ++i) scanf("%d",&jump[i]);
visit[1] = true, q.push(1);
for(;!q.empty()&&!visit[N];++time){
size = q.size();
for(i = 0; i < size; ++i){
c = q.front();
q.pop();
for(j = c+1; j <= c+jump[c]; ++j)
if(!visit[j]) visit[j] = true, q.push(j);
}
}
visit[N] ? printf("%d",time) : printf("-1");
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/11060/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.