Cod sursa(job #637067)

Utilizator Teodor94Teodor Plop Teodor94 Data 20 noiembrie 2011 11:27:32
Problema DreptPal Scor 40
Compilator cpp Status done
Runda .com 2011 Marime 1.03 kb
#include<cstdio>

const int N = 1002;

int a[N][N], n, m;

void citire() {
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            scanf("%d", &a[i][j]);
}

bool palind(int lin, int y1, int y2) {
    while (a[lin][y1] == a[lin][y2] && y1 < y2) {
        ++y1;
        --y2;
    }

    if (y1 >= y2)
        return true;

    return false;
}

int scmax(int y1, int y2) {
    int s = 0, smax = 0;

    for (int i = 1; i <= n; ++i) {
        if (s > smax)
            smax = s;

        if (palind(i, y1, y2))
            ++s;
        else
            s = 0;
    }

    return smax;
}

void rez() {
    int amax = 0;

    for (int j1 = 1; j1 <= m; ++j1)
        for (int j2 = j1; j2 <= m; j2 += 2) {
            int s = scmax(j1, j2);

            if ((j2 - j1 + 1) * s > amax)
                amax = (j2 - j1 + 1) * s;
        }

    printf("%d\n", amax);
}

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

    citire();

    rez();

    return 0;
}