Cod sursa(job #1681221)

Utilizator preda.andreiPreda Andrei preda.andrei Data 9 aprilie 2016 12:25:34
Problema Plantatie Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <iostream>
#include <cstdio>

using namespace std;

int mat[501][501];
int maxim[501][25];

int main()
{
    FILE *fin = fopen("plantatie.in", "r");
    FILE *fout = fopen("plantatie.out", "w");

    int n, t, x, y, lat, rez, col1, col2;

    fscanf(fin, "%d%d", &n, &t);
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            fscanf(fin, "%d", &mat[i][j]);
            if(mat[i][j] > maxim[i][(j - 1) / 25])
                maxim[i][(j - 1) / 25] = mat[i][j];
        }
    }

    while(t--){
        fscanf(fin, "%d%d%d", &x, &y, &lat);
        rez = 0;

        col1 = y;
        col2 = y + lat - 1;

        for(int i = x; i < x + lat; ++i){
            for(int j = col1; j <= col2 && j <= (col1 - 1) / 25 * 25; ++j)
                if(mat[i][j] > rez)
                    rez = mat[i][j];
            for(int j = col2; j >= col1 && j > ((col2 - 1) / 25 - 1) * 25; --j)
                if(mat[i][j] > rez)
                    rez = mat[i][j];
            for(int j = (col1 - 1) / 25 + 1; j <= (col2 - 1) / 25 - 1; ++j)
                if(maxim[i][j] > rez)
                    rez = maxim[i][j];
        }
        fprintf(fout, "%d\n", rez);
    }


    return 0;
}