-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumSquare.java
More file actions
53 lines (47 loc) · 1.67 KB
/
Copy pathNumSquare.java
File metadata and controls
53 lines (47 loc) · 1.67 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
package algorithm.baek.brute;
import algorithm.TestCase;
import java.io.*;
import java.text.ParseException;
import java.util.StringTokenizer;
/**
* https://www.acmicpc.net/problem/1051
* 숫자 정사각형
* 브루트포스
*/
public class NumSquare implements TestCase {
static int n, m;
static int[][] arr;
static int max = 1;
@Override
public void test() throws ParseException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
arr = new int[n][m];
for (int i = 0; i < n; i++) {
String[] str = br.readLine().split("");
for (int j = 0; j < m; j++) {
arr[i][j] = Integer.parseInt(str[j]);
}
}
int min = Math.min(n, m);
for (int y = 0; y < n; y++) {
for (int x = 0; x < m - 1; x++) {
for (int size = 1; size < min; size++) {
if (y + size < n && x + size < m) {
if (arr[y][x] == arr[y][x + size]
&& arr[y][x] == arr[y + size][x]
&& arr[y][x] == arr[y + size][x + size]) {
max = Math.max(max, (size + 1) * (size + 1));
}
}
}
}
}
bw.write(max + "\n");
bw.flush();
bw.close();
}
}