对于一个字符矩阵,其中的一些字符构成字母 Y 是指存在一个中间字符,从这个中间字符向下、向左上(45度)、向右上(45度)的字符都与中间的字符相同。
字母 Y 的长度指同时向 3 个方向的相同字母延伸的最大距离。
例如,下图中所有的 1 组成一个字母 Y,长度为 3。
又如,下图中以第 5 行第 6 列为中心也构成一个字母 Y (由字符 A 构成),长度为 1 。
再如,下图中以第 4 行第 3 列为中心也构成一个字母 Y (由字符 0 构成),长度为 2 。
blablabla
样例
7 7
1000001
0100010
0010100
0001AAA
00010A0
00010A0
00010A0
3
import java.util.Scanner;
/*
7 7
1000001
0100010
0010100
0001AAA
00010A0
00010A0
00010A0
*/
public class test1 {
static final int N = 1010;
static int n, m;
static char[][] a = new char[N][N];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
for (int i = 0; i < n; i ++ ) {
String str = sc.next();
for (int j = 0; j < m; j ++ ) {
a[i][j] = str.charAt(j);
}
}
int ans = 0;
for (int i = 0; i < n; i++ ) {
for (int j = 0; j < m; j ++ ) {
ans = Math.max(ans, dfs(i, j, 0));
}
}
System.out.println(ans);
}
public static int dfs(int i, int j, int ji) {
for (int x1 = i - 1, y1 = j - 1, x2 = i - 1, y2 = j + 1, x3 = i + 1, y3 = j;
FX(x1, y1) && FX(x2, y2) && FX(x3, y3); x1 -- , y1 --, x2 --, y2 ++ , x3 ++ ) {
if (a[i][j] == a[x1][y2] && a[i][j] == a[x2][y2] && a[i][j] == a[x3][y3]) {
ji ++ ;
} else {
break;
}
}
return ji;
}
public static boolean FX(int x, int y) {
if (x >= 0 && x < n && y >= 0 && y < m) return true;
else return false;
}
}