UVA – 10074 – Take the Land

#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#define FOR(ii, i0, in) for((ii)=(i0); (ii)<(in); (ii)++)
#define FOR2d(ii, jj, i0, j0, in, jn) FOR(ii, i0, in) FOR(jj, j0, jn)
using namespace std;

int main() {
	int I, J, i, j, k;
	while ((cin >> I >> J) && I && J) {
		int a[I][J], MAX=0;
		FOR2d(i, j, 0, 0, I, J){
			cin >> a[i][j];
			a[i][j] = (i && !a[i][j]) ? a[i - 1][j] + 1 : !a[i][j];
		}
		FOR2d(i, j, 0, 0, I, J){
			int count = 1;
			for (k = j + 1; k  < J && a[i][j] <= a[i][k]; k++)	count++;
			for (k = j - 1; k >= 0 && a[i][j] <= a[i][k]; k--)	count++;
			MAX = max(count*a[i][j], MAX);
		}
		cout << MAX << endl;
	}
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: