Code: Select all
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
freopen("lielkva.dat", "r", stdin);
freopen("lielkva.rez", "w", stdout);
string lastRow;
string currentRow;
vector<int> lastCount;
vector<int> currentCount;
int n, max = 1;
cin >> n;
cin >> lastRow;
for (int i = 0; i < n; i++)
{
lastCount.push_back(1);
currentCount.push_back(1);
}
for (int i = 1; i < n; i++)
{
cin >> currentRow;
currentCount[0] = 1;
for (int j = 1; j < n; j++)
{
if (currentRow[j] == currentRow[j-1] &&
currentRow[j] == lastRow[j] &&
currentRow[j] == lastRow[j-1])
{
currentCount[j] = min(currentCount[j-1], min(lastCount[j], lastCount[j-1])) + 1;
}
else
{
currentCount[j] = 1;
}
if (currentCount[j] > max)
{
max = currentCount[j];
}
}
lastCount = currentCount;
lastRow = currentRow;
}
cout << max;
return 0;
};