-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJava_14890.java
More file actions
59 lines (54 loc) · 1.59 KB
/
Copy pathJava_14890.java
File metadata and controls
59 lines (54 loc) · 1.59 KB
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 src;
import java.util.Scanner;
public class Java_14890 {
static int N,L;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
L=sc.nextInt();
int[][] map = new int[N][N];
int[][] map2 = new int[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
map[i][j]= sc.nextInt();
map2[j][i]=map[i][j];
}
} // 입력
int road=0;
for (int i = 0; i <N ; i++) {
if(isPossibleRoad(map[i]))road++;
if(isPossibleRoad(map2[i]))road++;
}
System.out.print(road);
}
static boolean isPossibleRoad(int[] map){
int previousH=map[0],cnt=1,j=1;
while (j<N){
if(previousH==map[j]){
cnt++;
j++;
}
else if(previousH>map[j]){ // 내리막길
if(previousH-map[j]!=1)return false;
previousH=map[j];
int currentH=map[j];
for (int i = j; i <L+j ; i++) {
if(i>=N ||currentH!=map[i]) return false;
}
cnt=0;
j+=L;
}
else if(previousH<map[j]){ // 오르막길
if(map[j]-previousH!=1)return false;
if(L<=cnt){
previousH=map[j];
cnt=1;
j++;
}
else return false;
}
if(j==N) break;
}
return true;
}
}