Repository navigation
Expand file tree
/
Copy pathswea_2117.java
More file actions
85 lines (79 loc) · 1.66 KB
/
Copy pathswea_2117.java
File metadata and controls
85 lines (79 loc) · 1.66 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
package practice;
import java.util.*;
// SWEA, 2117, 홈 방범 서비스
public class pp {
static int n, m, g[][], cnt, max = (int) -1e9;
static boolean isRange(int x, int y) {
if (x >= 0 && x < n && y >= 0 && y < n) {
return true;
}
return false;
}
static void check(int x, int y, int k) {
int upx = 0;
int downx = 0;;
int upy = 0;
int downy = 0;
cnt = 0;
for (int i = 1; i < k - 1; i++) {
upx = x - i;
downx = x + i;
for (int j = k - 1 - i; j > 0; j--) {
upy = y + j;
downy = y - j;
if (isRange(upx, upy) && g[upx][upy] == 1) {
cnt++;
}
if (isRange(upx, downy) && g[upx][downy] == 1) {
cnt++;
}
if (isRange(downx, upy) && g[downx][upy] == 1) {
cnt++;
}
if (isRange(downx, downy) && g[downx][downy] == 1) {
cnt++;
}
}
}
for (int i = - k + 1; i < k; i++) {
if (i == 0) {
continue;
}
if (isRange(x + i, y) && g[x + i][y] == 1) {
cnt++;
}
if (isRange(x, y + i) && g[x][y + i] == 1) {
cnt++;
}
}
if (isRange(x, y) && g[x][y] == 1) {
cnt++;
}
if ((k * k) + (k - 1) * (k - 1) <= cnt * m ) {
max = Math.max(max, cnt);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tt = 0; tt < t; tt++) {
max = 0;
n = sc.nextInt();
m = sc.nextInt();
g = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
g[i][j] = sc.nextInt();
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 1; k <= n + 1; k++) {
check(i, j, k);
}
}
}
System.out.println("#" + (tt + 1) + " " + max);
}
}
}