Pagini recente » Cod sursa (job #336423) | Cod sursa (job #399364) | Cod sursa (job #530209) | Cod sursa (job #198821) | Cod sursa (job #2312627)
#include <bits/stdc++.h>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
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()
{
InParser f ("dreptpal.in");
f>>n>>m;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
f>>v[i][j];
++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;
}