详解请看 http://blog.sina.com.cn/s/blog_9aa2786a01011zoj.html
const int N = 2010;
int n, m, Ans1, Ans2, top, sta1[N], sta2[N], h[N];
bool Dat[N][N];
inline void Input() {
scanf("%d%d", &n, &m);
int x;
For(i, 1, n)
For(j, 1, m) {
scanf("%d", &x);
Dat[i][j] = x;
}
}
inline void push(int h) {
int x = 1;
while(sta2[top] > h) {
Ans1 = max(sqr(min(sta2[top], sta1[top])), Ans1), Ans2 = max(sta2[top] * sta1[top], Ans2);
if(sta2[--top] >= h) sta1[top] += sta1[top+1];
else {
x += sta1[top+1];
break;
}
}
if(sta2[top] == h) sta1[top] += x;
else sta2[++top] = h, sta1[top] = x;
}
inline void Solve() {
int now = 0;
Ans1 = 1, Ans2 = 1;
For(i, 1, m) {
if (Dat[1][i] + Dat[1][i-1] == 1) now++;
else now = 1;
Ans2 = max(now, Ans2), h[i] = 1;
}
For(i, 2, n) {
For(j, 1, m) {
if(Dat[i][j] + Dat[i][j-1] != 1) push(0);
if(Dat[i][j] + Dat[i-1][j] == 1) h[j]++;
else h[j] = 1;
push(h[j]);
}
push(0);
}
printf("%d\n%d\n", Ans1, Ans2);
}
int main() {
#ifndef ONLINE_JUDGE
SETIO("1057");
#endif
Input();
Solve();
return 0;
}