#ifdef ONLINE_JUDGE #include #else #include #include #include #include #include #include #include #include #include #include #include #include #include #endif using namespace std; // lambda : [] (int a, int b) -> bool { body return } // string r_str = R"(raw string)" #define mp make_pair #define eb emplace_back #define pb push_back #define LL long long #define ULL unsigned long long #define BASE 73 #define NMAX 10000 #define NMAX2 20001 #define MOD1 1000000007 #define ALL(V) (V).begin(), (V).end() #define ALLR(V) (V).rbegin(), (V).rend() #define CRLINE Duxar(__LINE__); #define SHOWME(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl; #define ENTER putchar('\n'); void Duxar(int _this_line) { #ifndef ONLINE_JUDGE printf("\n . . . . . . . . . . . . . Passed line - %d\n", _this_line); #endif } template void ReadNo(T &_value) { T sign = 1; char ch; _value = 0; while(!isdigit(ch = getchar())) { (ch == '-') && (sign = -1); } do { _value = _value * 10 + (ch - '0'); } while(isdigit(ch = getchar())); _value *= sign; } template void AddNr(T &a, T b) { a = a + b; while (a >= MOD1) { a -= MOD1; } while (a < 0) { a += MOD1; } } int N, M, T, val, ans1, par; char farm[401][401]; int values[401][401], parent[401][401]; vector > que; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; int main(){ #ifndef ONLINE_JUDGE freopen("input.cpp", "r", stdin); #endif int i, st, dr, j, k, tox, toy, x, y, z; cin >> T; cin >> N >> M; que.resize(N * M); for (i = 0; i < N; ++i) { cin >> farm[i]; } for (i = 0; i < N; ++i) { for (j = 0; j < M; ++j) { if (values[i][j] == 0) { ++par; st = dr = 0; que[0] = {i, j}; val = 0; values[i][j] = -1; while (st <= dr) { x = que[st].first; y = que[st].second; ++st; ++val; for (k = 0; k < 4; ++k) { tox = x + dx[k]; toy = y + dy[k]; if (0 <= tox && tox < N && 0 <= toy && toy < M) { if (values[tox][toy] == 0 && farm[x][y] == farm[tox][toy]) { ++dr; que[dr] = {tox, toy}; values[tox][toy] = -1; } } } } ans1 = max(ans1, val); for (k = 0; k < st; ++k) { values[que[k].first][que[k].second] = val; parent[que[k].first][que[k].second] = par; } } } } if (T == 1) { cout << ans1; ENTER } else { int ans2 = 0; pair pr; char col; for (i = 0; i < N; ++i) { for (j = 0; j < M; ++j) { for (k = 0; k < 4; ++k) { x = i + dx[k]; y = j + dy[k]; if (0 <= x && x < N && 0 <= y && y < M) { for (z = 0; z < 4; ++z) { tox = i + dx[z]; toy = j + dy[z]; if (0 <= tox && tox < N && 0 <= toy && toy < M) { if (farm[i][j] != farm[x][y] && farm[x][y] == farm[tox][toy]) { if (parent[x][y] != parent[tox][toy]) { if (ans2 < values[x][y] + values[tox][toy] + 1) { ans2 = values[x][y] + values[tox][toy] + 1; pr = {i + 1, j + 1}; col = farm[x][y]; } } else { if (ans2 < values[x][y] + 1) { ans2 = values[x][y] + 1; pr = {i + 1, j + 1}; col = farm[x][y]; } } } } } } } } } cout << pr.first << ' ' << pr.second; ENTER cout << col; ENTER } return 0; }