728x90
package a0303;
import java.util.*;
/*
도착점 지시사항 따라 계속 가는게 아니라
주사위 던진 직후만 한번더 지시사항 따르는것인듯?
*/
public class B5566주사위게임 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int turn = sc.nextInt();
int[] arr = new int[size];
for(int i=0; i<size; i++) {
arr[i] = sc.nextInt();
}
int nowidx = 0;
int cnt = 0;
for(int i=1; i<=turn; i++) {
int now = sc.nextInt();
nowidx+=now;
if(nowidx>=size-1) {
cnt = i;
break;
}
int gomore = arr[nowidx];
nowidx+=gomore;
if(nowidx>=size-1) {
cnt = i;
break;
}
}
System.out.println(cnt);
}
}
'알고리즘 문제풀이' 카테고리의 다른 글
[알고리즘] 백준1986 - 체스 java (0) | 2022.03.15 |
---|---|
[알고리즘] 백준1063 - 킹 java (0) | 2022.03.03 |
[알고리즘] 백준1347 - 미로탐색 java (0) | 2022.03.03 |
[알고리즘] 백준2606 - 바이러스 java (0) | 2022.03.03 |
[알고리즘] 백준1759 - 암호만들기 java (0) | 2022.03.01 |