#include #include int l = 0, m, n, nrc = 0; int b[400][400]; char a[400][401]; char c[26]; void Lee(char, int, int); void Init(); void GetCrops(); int main() { int type, i, j, is = 0, js = 0, k; unsigned long int max = 0; char a2[2], cs; scanf("%d%d%d", &type, &m, &n); gets(a2); for (i = 0; i < m; i++) gets(a[i]); // for (i = 0; i < m; i++) // puts(a[i]); if (type == 1) { Init(); for (i = 0; i < m; i++) for (j = 0; j < n; j++) { if (b[i][j] == 0) Lee(a[i][j], i, j); if (max < l) max = l; l = 0; } printf("%lu", max); } else if (type == 2) { //GetCrops(); for (i = 0; i < m; i++) for (j = 0; j < n; j++) { if (j+1 < n) if (a[i][j+1] != a[i][j]) { Init(); Lee(a[i][j+1], i, j); if ((l > max) || ((l == max) && (cs > a[i][j+1]))) { is = i; js = j; max = l; cs = a[i][j+1]; } } if (j-1 >= 0) if ((a[i][j-1] != a[i][j+1]) && (a[i][j-1] != a[i][j])) { Init(); Lee(a[i][j-1], i, j); if ((l > max) || ((l == max) && (cs > a[i][j-1]))) { is = i; js = j; max = l; cs = a[i][j-1]; } } if (i+1 < m) if ((a[i+1][j] != a[i][j]) && (a[i+1][j] != a[i][j+1]) && (a[i+1][j] != a[i][j-1])) { Init(); Lee(a[i+1][j], i, j); if ((l > max) || ((l == max) && (cs > a[i+1][j]))) { is = i; js = j; max = l; cs = a[i+1][j]; } } if (i-1 >= 0) if ((a[i-1][j] != a[i][j]) && (a[i-1][j] != a[i+1][j]) && (a[i-1][j] != a[i][j-1]) && (a[i-1][j] != a[i][j+1])) { Init(); Lee(a[i-1][j], i, j); if ((l > max) || ((l == max) && (cs > a[i-1][j]))) { is = i; js = j; max = l; cs = a[i-1][j]; } } } printf("%d %d\n%c", is+1, js+1, cs); } return 0; } void Lee(char c, int i, int j) { l += 1; b[i][j] = 1; //Right if ((j + 1) < n) if ((a[i][j+1] == c) && (b[i][j+1] == 0)) Lee(c, i, j+1); //Left if ((j-1) >= 0) if ((a[i][j-1] == c) && (b[i][j-1] == 0)) Lee(c, i, j-1); //Up if ((i-1) >= 0) if ((a[i-1][j] == c) && (b[i-1][j] == 0)) Lee(c, i-1, j); //Down if ((i+1) < m) if ((a[i+1][j] == c) && (b[i+1][j] == 0)) Lee(c, i+1,j); } void Init() { int i, j; l = 0; for (i = 0; i < m; i++) for(j = 0; j < n; j++) b[i][j] = 0; } void GetCrops() { int found, i, j, k; for (i = 0; i < m; i++) for (j = 0; j < n; j++) { found = 0; for (k = 0; k < nrc; k++) if (a[i][j] == c[k]) found = 1; if (found == 0) { nrc += 1; c[nrc-1] = a[i][j]; } } }