#include <iostream>
#include <stack>
#include <ctime>
using namespace std;
typedef struct point{
int x,y;
} point;
int M,N;
int map[2000][2000];
int now[2000];
int res;
stack<point> sta;
void show(int count){
for(int i = 0; i<=count; ++i){
printf("%4d",now[i]);
}
printf("\n");
}
void solve(int count){
int high,temp,width;
stack<point> sta;
point p1,p2;
p1.x = 1;
high = p1.y = now[0];
sta.push(p1);
for(int i = 1; i <= count; ++i){
if(high < now[i]){
p1.x = 1;
high = p1.y = now[i];
sta.push(p1);
}else{
p1 = sta.top(); sta.pop();
if(p1.x * p1.y > res){
res = p1.x * p1.y;
}
width = p1.x;
if(sta.size()!=0){
p1 = sta.top();
high = p1.y;
}else{
high = 0;
}
while(high >= now[i]){
sta.pop();
p1.x = p1.x + width;
if(p1.x * p1.y > res){
res = p1.x * p1.y;
}
width = p1.x;
if(sta.size() != 0){
p1 = sta.top();
high = p1.y;
}else{
high = 0;
}
}
p1.x = 1 + width;
high = p1.y = now[i];
sta.push(p1);
}
}
width = 0;
if(now[0] == 2 && now[1]==2 && now[2] == 1){
p1 =sta.top();
}
while(sta.size()){
p1 = sta.top(); sta.pop();
p1.x = p1.x + width;
if(p1.x * p1.y > res){
res = p1.x * p1.y;
}
width = p1.x;
}
}
int main(){
clock_t start,finish;
start=clock();
freopen("a.txt","r",stdin);
freopen("b.txt","w",stdout);
int i,j,k,temp,count,t;
while(scanf("%d %d",&M,&N) != EOF){
for(i = 0; i < M; ++i){
for(j = 0; j < N; ++j){
scanf("%d",&map[i][j]);
}
}
for(i = 1; i < M; ++i){
for(j = 0; j < N; ++j){
if( map[i][j] == 1 && map[i-1][j]!=0){
map[i][j] += map[i-1][j];
}
}
}
res = 0;
for(i = 0; i < M; ++i){
count = -1;
for(j = 0; j < N; ++j){
if(map[i][j] != 0 ){
now[++count] = map[i][j];
}else if(count>=0){
solve(count);
count = -1;
}
}
if(count != -1){
solve(count);
}
}
printf("%d\n",res);
}
finish=clock();
cout << finish-start << "/" << CLOCKS_PER_SEC << " (s) "<< endl;
return 0;
}
POJ 3494(可以过)
最新推荐文章于 2022-01-15 13:35:08 发布