Pagini recente » Cod sursa (job #3128689) | Cod sursa (job #68183) | Cod sursa (job #269117) | Cod sursa (job #393873) | Cod sursa (job #2312625)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("dreptpal.in");
ofstream g ("dreptpal.out");
const int nmax=1e3+3;
int n,m,v[nmax][nmax],d[nmax][nmax],c,r,mr,sol;
stack <int> st;
int main()
{
f>>n>>m;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j) f>>v[i][j];
}
for(int i=1;i<=n;++i)
{
c=r=0;
for(int j=1;j<=m;++j)
{
if(r>=j) mr=2*c-j;
d[i][j]=min(m-j,d[i][mr]);
d[i][j]=max(d[i][j],1);
while(v[i][j-d[i][j]]==v[i][j+d[i][j]]&&j-d[i][j]>=1&&j+d[i][j]<=m) ++d[i][j];
if(i+d[i][j]-1>r)
{
c=i;
r=i+d[i][j]-1;
}
}
}
for(int j=1;j<=m;++j)
{
sol=max(sol,d[1][j]*2-1);
st.push(1);
for(int i=2;i<=n+1;++i)
{
while(!st.empty()&&(d[i][j]<d[st.top()][j]))
{
sol=max(sol,(i-st.top())*(d[st.top()][j]*2-1));
st.pop();
}
st.push(i);
}
while(!st.empty()) st.pop();
}
g<<sol;
return 0;
}