-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2117_홈 방범 서비스.cpp
66 lines (54 loc) · 1.08 KB
/
2117_홈 방범 서비스.cpp
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
#include <iostream>
using namespace std;
int n, m;
int map[20][20];
bool isWall(int x, int y)
{
return x < 0 || x >= n || y < 0 || y >= n;
}
int secure(int x, int y, int k)
{
int cost = k * k + (k - 1) * (k - 1);
int cnt = 0;
// 서비스 제공 가능한 집을 찾는다
int d[] = { -1, 1 };
for (int i = 0; i < k; i++) {
for (int j = 0; j < 2; j++) {
int nx = x + i * d[j];
int ny = y;
if (isWall(nx, ny)) continue;
int num = k - i - 1;
for (int l = ny - num; l <= ny + num; l++) {
if (!isWall(nx, l) && map[nx][l])
cnt++;
}
if (i == 0) break;
}
}
if (cnt * m < cost)
return 0;
return cnt;
}
int main()
{
int T;
cin >> T;
for (int test_case = 1; test_case <= T; test_case++) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
}
}
int answer = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 1; k <= n + 1; k++) {
answer = max(answer, secure(i, j, k));
}
}
}
cout << "#" << test_case << " " << answer << "\n";
}
return 0;
}