Cod sursa(job #1727851)

Utilizator cristina_borzaCristina Borza cristina_borza Data 11 iulie 2016 19:23:41
Problema Teren Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>
#include <cstdio>

using namespace std;

int mat[305][305];
int n , m , nr , x , sol;

void read(int &x) {
    char ch;
    x = 0;

    while (!isdigit(ch = getchar())) {

    }

    do {
        x = x * 10 + ch - '0';
    } while (isdigit(ch = getchar()));
}

int main() {
    freopen("teren.in" , "r" , stdin);
    freopen("teren.out" , "w" , stdout);

    read(n) , read(m) , read(nr);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            read(x);
            mat[i][j] = x + mat[i][j - 1] + mat[i - 1][j] - mat[i - 1][j - 1];
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            int pos = i , st = 0 , aux = 0;
            for (int k = 1; k <= j; ++k) {
                st = mat[i][j] - mat[i][k - 1] - mat[pos][j] + mat[pos][k - 1];
                while (pos > 0 && st + mat[pos][j] - mat[pos - 1][j] - mat[pos][k - 1] + mat[pos - 1][k - 1] <= nr) {
                    st += mat[pos][j] - mat[pos - 1][j] - mat[pos][k - 1] + mat[pos - 1][k - 1];
                    --pos;
                }

                sol = max(sol , (j - k + 1) * (i - pos));
            }
        }
    }

    printf("%d" , sol);
    return 0;
}