Cod sursa(job #2453010)

Utilizator andreiomd1Onut Andrei andreiomd1 Data 2 septembrie 2019 10:39:48
Problema Balans Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <fstream>
#include <iomanip>

using namespace std;

ifstream f("balans.in");
ofstream g("balans.out");

const int NMAX =15e1 + 5;

int N, M, L, C;

long long A[NMAX][NMAX];

long double ans = 0;

static inline long long Sum (int X1, int Y1, int X2, int Y2)
{
    return 1LL * (A[X2][Y2] - A[X2][Y1 - 1] - (A[X1 - 1][Y2] - A[X1 - 1][Y1 - 1]));
}

int main()
{
    f.tie(NULL);

    f >> N >> M >> L >> C;

    for(int i = 1; i <= N; ++i)
        for(int j = 1; j <= M; ++j)
            f >> A[i][j];

    for(int i = 1; i <= N; ++i)
        for(int j = 1; j <= M; ++j)
            A[i][j + M] = A[i + N][j] = A[i + N][j + M] = A[i][j];

    for(int i = 1; i < 2 * N; ++i)
        for(int j = 1; j < 2 * M; ++j)
            A[i][j] += (A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1]);

    for(int l = L; l <= N; ++l)
        for(int c = C; c <= M; ++c)
            for(int l1 = 1, l2 = l; l1 <= N; ++l1, ++l2)
                for(int c1 = 1, c2 = c; c1 <= M; ++c1, ++c2)
                {
                    long double Numa = Sum(l1, c1, l2, c2);
                    long double Numb = l * c;

                    ans = max(ans, (long double)(Numa / Numb));
                }

    g << setprecision(3) << fixed;

    g << ans << '\n';

    return 0;
}