[BOJ] 14890. 경사로 - Simulation
제출일 : 2019-10-14
문제 풀이 시간 : 2H
난이도 : ★★★★☆
Problem
Input
첫째 줄에 N (2 ≤ N ≤ 100)과 L (1 ≤ L ≤ N)이 주어진다. 둘째 줄부터 N개의 줄에 지도가 주어진다. 각 칸의 높이는 10보다 작거나 같은 자연수이다.
Output
첫째 줄에 지나갈 수 있는 길의 개수를 출력한다.
Example
input
6 2
3 3 3 3 3 3
2 3 3 3 3 3
2 2 2 3 2 3
1 1 1 2 2 2
1 1 1 3 3 1
1 1 2 3 3 2
output
3
Solution & Inpression
해결하지 못한 문제.
Code
언어 : JAVA
메모리 : 25,868 kb
실행시간 : 240 ms
import java.util.*;
public class Main {
static int[][] wheels;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
wheels = new int[5][8];
for (int import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static int N, L;
static int[][] map;
static boolean[][] visitRow, visitCol;
static ArrayList<int[]> v;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
L = sc.nextInt();
map = new int[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
map[i][j] = sc.nextInt();
}
}
int ans = 0;
int j = 0;// 끝에 도착시 j로 체크
for (int i = 0; i < N; i++) {
int cnt = 1;
for (j = 0; j < N-1; j++) { //가로: 좌->우
if(map[i][j] ==map[i][j+1]) cnt++; //평지
else if(map[i][j]+1==map[i][j+1] && cnt>= L) cnt=1; //오르막
else if(map[i][j]-1==map[i][j+1] && cnt>= 0) cnt=-L+1; //내리막
else break;
}
if(j==N-1 && cnt>= 0) ans++; //끝에 도착
cnt=1;
for (j = 0; j < N-1; j++) { //세로: 상->하
if(map[j][i] ==map[j+1][i]) cnt++; //평지
else if(map[j][i]+1==map[j+1][i] && cnt>= L) cnt=1; //오르막
else if(map[j][i]-1==map[j+1][i] && cnt>= 0) cnt=-L+1; //내리막
else break;
}
if(j==N-1 && cnt>= 0) ans++; //끝에 도착
}
System.out.println(ans);
}
}
'Problem > BOJ' 카테고리의 다른 글
[BOJ] 16235. 나무 재테크 - Simultaion (0) | 2019.10.16 |
---|---|
[BOJ] 14891. 톱니바퀴 - Simulation (0) | 2019.10.14 |
[BOJ] 14889. 스타트와 링크- Permutation (0) | 2019.10.14 |
[BOJ] 14888. 연산자끼워넣기 - Permutation (0) | 2019.10.14 |
[BOJ] 1157. 단어공부 - Array (0) | 2019.10.08 |