Pagini recente » Cod sursa (job #2154469) | Cod sursa (job #1481330) | Cod sursa (job #1723296) | Cod sursa (job #1856558) | Cod sursa (job #3304332)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("dreptpal.in");
ofstream fout("dreptpal.out");
const int NMAX = 1005;
int n, m, a[NMAX][NMAX], pal[NMAX][NMAX], st[NMAX], dr[NMAX], ans = -1;
int main()
{
fin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
fin >> a[i][j];
for(int i = 1; i <= n; i++)
{
a[i][0] = 1e9 + 1;
a[i][m + 1] = 1e9 - 1;
for(int j = 1; j <= m; j++)
{
int st = j - 1, dr = j + 1;
while(a[i][st] == a[i][dr])
st--, dr++;
pal[i][j] = dr - st - 1;
}
}
for(int j = 1; j <= m; j++)
{
stack<int> stk;
for(int i = 1; i <= n; i++)
{
while(!stk.empty() && pal[stk.top()][j] >= pal[i][j])
stk.pop();
st[i] = (stk.empty() ? 0 : stk.top());
stk.push(i);
}
while(!stk.empty())
stk.pop();
for(int i = n; i >= 1; i--)
{
while(!stk.empty() && pal[stk.top()][j] >= pal[i][j])
stk.pop();
dr[i] = (stk.empty() ? n + 1 : stk.top());
stk.push(i);
}
for(int i = 1; i <= n; i++)
ans = max(ans, pal[i][j] * (dr[i] - st[i] - 1));
}
fout << ans;
fin.close();
fout.close();
return 0;
}