- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14890.java
More file actions
Latest commit
129 lines (94 loc) · 2.4 KB
/
Copy path14890.java
File metadata and controls
129 lines (94 loc) · 2.4 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
importjava.util.*;
publicclassMain {
publicstaticvoidmain(String[] arg) {
Scannersc = newScanner(System.in);
intn = sc.nextInt();
intl = sc.nextInt();
int[][] map = newint[n][n];
boolean[][] used = newboolean[n][n];
for(inti=0; i<n; i++) {
for(intj=0; j<n; j++) {
map[i][j] = sc.nextInt();
}
}
intanswer = 0;
// row check
for(inti=0; i<n; i++) {
booleanpossible = true;
intj = 0;
while(possible && j+1 < n) {
if(map[i][j] == map[i][j+1]) {
j++;
}
elseif(map[i][j] > map[i][j+1]) {
possible = false;
// j+1부터 (포함) l개가 아직 경사로를 안썼고, 크기가 1 작아야함
intk=0;
while(k!=l && j+1+k<n && !used[i][j+1+k] && map[i][j]-1 == map[i][j+1+k]) {
used[i][j+1+k] = true;
k++;
}
if(k == l && j+l < n) {
j += l;
possible = true;
}
}
elseif(map[i][j] < map[i][j+1]) {
possible = false;
// j부터 (포함) 뒤로 l개가 아직 경사로를 안썼고, 크기가 1 작아야함
intk=0;
while(k!=l && j-k>=0 && !used[i][j-k] && map[i][j-k]+1 == map[i][j+1]) {
used[i][j-k] = true;
k++;
}
if(k == l && j+1 < n) {
j++;
possible = true;
}
}
}
if(possible)
answer++;
}
// col check
used = newboolean[n][n];
for(intj=0; j<n; j++) {
booleanpossible = true;
inti = 0;
while(possible && i+1 < n) {
if(map[i][j] == map[i+1][j]) {
i++;
}
elseif(map[i][j] > map[i+1][j]) {
possible = false;
// i+1부터 (포함) l개가 아직 경사로를 안썼고, 크기가 1 작아야함
intk=0;
while(k!=l && i+1+k<n && !used[i+1+k][j] && map[i][j]-1 == map[i+1+k][j]) {
used[i+1+k][j] = true;
k++;
}
if(k == l && i+l < n) {
i += l;
possible = true;
}
}
elseif(map[i][j] < map[i+1][j]) {
possible = false;
// i부터 (포함) 뒤로 l개가 아직 경사로를 안썼고, 크기가 1 작아야함
intk=0;
while(k!=l && i-k>=0 && !used[i-k][j] && map[i-k][j]+1 == map[i+1][j]) {
used[i-k][j] = true;
k++;
}
if(k == l && i+1 < n) {
i++;
possible = true;
}
}
}
if(possible)
answer++;
}
System.out.println(answer);
}
}