Pagini recente » Borderou de evaluare (job #2014420) | Borderou de evaluare (job #2007193) | Borderou de evaluare (job #1651920) | Borderou de evaluare (job #1208596) | Cod sursa (job #635420)
Cod sursa(job #635420)
#include<cstdio>
#include<deque>
#include<utility>
using namespace std;
int n,m,i,j,k,l,ok,sol,q,L[1010],pal(int,int);
deque<pair<int, pair<int,int> > > Q;
void read(),solve();
int main()
{
read();
solve();
return 0;
}
void read()
{
freopen("dreptpal.in","r",stdin);
freopen("dreptpal.out","w",stdout);
scanf("%d%d",&n,&m);
}
void solve()
{
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%d",&L[j]);
}
q=Q.size();
for(k=1;k<=m-2;k++)
{
for(l=k+2;l<=m;l+=2)
{
if(pal(k,l))
{
ok=0;
for(deque<pair<int, pair<int,int> > >::iterator it=Q.begin();it!=Q.begin()+q;it++)
{
pair<int,pair<int,int> > curr=*it;
if(curr.second.first==k && curr.second.second==l)
{
Q.push_back(make_pair(curr.first+1,make_pair(k,l)));
if((l-k+1)*(curr.first+1)>sol)sol=(l-k+1)*(curr.first+1);
ok=1;
break;
}
}
if(!ok)
{
Q.push_back(make_pair(1,make_pair(k,l)));
if(l-k+1>sol)sol=l-k+1;
}
}
}
}
for(;q--;)Q.pop_front();
}
if(sol<n)sol=n;
printf("%d\n",sol);
}
int pal(int beg,int end)
{
while(beg<end)
{
if(L[beg]==L[end]){beg++;end--;}
else return 0;
}
return 1;
}