Pagini recente » Cod sursa (job #1450981) | Cod sursa (job #2315134) | Cod sursa (job #3223302) | Cod sursa (job #670688) | Cod sursa (job #2357453)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("submatrix.in");
ofstream fout("submatrix.out");
int a[105][105], t[105], n, m;
int main()
{
int i, j, L1, L2, h, Amax = 0;
int xs, ys, xd, yd, len;
char ch;
xs = ys = xd = yd = 0;
fin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j<= m; j++)
{
fin >> ch;
if (ch == '0') a[i][j] = 0;
else a[i][j] = 1 + a[i-1][j];
}
for (L1 = 1; L1 <= n; L1++)
for (L2 = L1; L2 <= n; L2++)
{
h = L2 - L1 + 1;
for (i = 1; i <= m; i++)
t[i] = a[L2][i] - a[L1 - 1][i];
/// aflu lungimea max a unei secvente din t
/// care au valorea h
len = 0;
for (i = 1; i <= m; i++)
{
if (t[i] == h) len++;
else len = 0;
if (len * h > Amax)
{
Amax = len * h;
xs = L1;
ys = i - len + 1;
xd = L2;
yd = i;
}
}
}
fout << Amax << "\n";
fout << xs << " " << ys << " " << xd << " " << yd << "\n";
fout.close();
return 0;
}