-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_14890.cpp
More file actions
159 lines (147 loc) · 4.86 KB
/
bj_14890.cpp
File metadata and controls
159 lines (147 loc) · 4.86 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// 경사로
#include <iostream>
#define MAX 101
using namespace std;
int map[MAX][MAX];
int rowVisited[MAX][MAX] = {false,};
int columnVisited[MAX][MAX] = {false,};
bool canGoCheck = false;
bool canPutCheck = false;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, l;
int answer = 0;
cin >> n >> l;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> map[i][j];
}
}
for (int i = 1; i <= n; i++) {
// 행
canGoCheck = true;
int cur = map[i][1];
int count = 1;
// 왼쪽 -> 오른쪽
for (int j = 2; j <= n; j++) {
if (map[i][j] == cur) count++;
else if (map[i][j] - cur == 1) {
if (count < l) {
canGoCheck = false;
break;
}
// 초기에 지날 때는 경사로가 있는지 확인할 필요 없음
for (int t = 1; t <= l; t++) rowVisited[i][j - t] = true; // 경사로를 놓은 곳 표시
cur = map[i][j];
count = 1;
} else if (map[i][j] - cur < 0) {
cur = map[i][j];
count = 1;
} else if(map[i][j] - cur > 1) {
canGoCheck = false;
break;
}
}
// 오른쪽 -> 왼쪽
if (canGoCheck) {
canPutCheck = true;
cur = map[i][n];
count = 1;
for (int j = n - 1; j >= 1; j--) {
if (map[i][j] == cur) count++;
else if (map[i][j] - cur == 1) {
if (count < l) {
canGoCheck = false;
break;
}
// 경사로를 놓기전 겹치는 부분이 있는지 확인
for (int t = 1; t <= l; t++) {
if (rowVisited[i][j + t]) {
canPutCheck = false;
break;
}
}
if (canPutCheck) {
for (int t = 1; t <= l; t++) rowVisited[i][j + t] = true; // 경사로를 놓은 곳 표시
cur = map[i][j];
count = 1;
} else {
canGoCheck = false;
break;
}
} else if (map[i][j] - cur < 0) {
cur = map[i][j];
count = 1;
} else if (map[i][j] - cur > 1) {
canGoCheck = false;
break;
}
}
if (canGoCheck) answer++;
}
// 열
// 위 -> 아래
canGoCheck = true;
canPutCheck = true;
cur = map[1][i];
count = 1;
for (int j = 2; j <= n; j++) {
if (map[j][i] == cur) count++;
else if (map[j][i] - cur == 1) {
if (count < l) {
canGoCheck = false;
break;
}
// 초기에 지날 때는 경사로가 있는지 확인할 필요 없음
for (int t = 1; t <= l; t++) columnVisited[j - t][i] = true; // 경사로를 높은 곳 표시
cur = map[j][i];
count = 1;
} else if (map[j][i] - cur < 0) {
cur = map[j][i];
count = 1;
} else if (map[j][i] - cur > 1) {
canGoCheck = false;
break;
}
}
if (canGoCheck) {
canPutCheck = true;
cur = map[n][i];
count = 1;
for (int j = n - 1; j >= 1; j--) {
if (map[j][i] == cur) count++;
else if (map[j][i] - cur == 1) {
if (count < l) {
canGoCheck = false;
break;
}
for (int t = 1; t <= l; t++) {
if (columnVisited[j + t][i]) {
canPutCheck = false;
break;
}
}
if (canPutCheck) {
for (int t = 1; t <= l; t++) columnVisited[j + t][i] = true;
cur = map[j][i];
count = 1;
} else {
canGoCheck = false;
break;
}
} else if (map[j][i] - cur < 0) {
cur = map[j][i];
count = 1;
} else if (map[j][i] - cur > 1) {
canGoCheck = false;
break;
}
}
if (canGoCheck) answer++;
}
}
cout << answer;
return 0;
}