Cod sursa(job #872341)

Utilizator 5t3fristea stefan 5t3f Data 5 februarie 2013 22:52:21
Problema Teren Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
// teren.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include "fstream"
using namespace std;
ifstream f("teren.in");
ofstream g("teren.out");
int nrl,nrc,mat[300][300],i,j,x;
void citire()
{
	f>>nrl>>nrc>>x;
	for(i=1;i<=nrl;i++)
		for(j=1;j<=nrc;j++)
			f>>mat[i][j];
}
void sume()
{
	int i, j;
    for(i=2;i<=nrl;i++){
        mat[i][1]+=mat[i-1][1];
    }
    for(j=2;j<=nrc;j++){
        mat[1][j]+=mat[1][j-1];
    }
    for(i=2;i<=nrl;i++){
        for(j=2;j<=nrc;j++){
            mat[i][j]=mat[i][j] + mat[i-1][j]+mat[i][j-1]- mat[i-1][j-1];
        }
    }
 
}
void aflare()
{
	int i1, j1, i2, j2, nr1, aria,maxi=0;
	for(i1=1;i1<=nrl;i1++)
	{
		for(j1=1;j1<=nrc;j1++)
		{
		  for(i2=i1;i2<=nrl;i2++)
		  {
			for(j2=j1;j2<=nrc;j2++)
			{
				nr1=mat[i2][j2] - mat[i2][j1-1] - mat[i1-1][j2] + mat[i1-1][j1-1];
 				if(nr1<=x)
				{
					aria= (i2-i1+1)*(j2-j1+1);
					if(aria>maxi)
						maxi=aria;
				}
				else{break;}
			}
		  }
		}
	}
	g<<maxi;
 
}
int main()
{
	citire();
	sume();
	aflare();
	return 0;
}