Cod sursa(job #1681200)

Utilizator preda.andreiPreda Andrei preda.andrei Data 9 aprilie 2016 12:18:02
Problema Plantatie Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 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;

    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;
        for(int i = x; i < x + lat; ++i){
            for(int j = (y - 1) / 25 + 1; j <= (y + lat - 2) / 25 - 1; ++j)
                if(maxim[i][j] > rez)
                    rez = maxim[i][j];
            for(int j = y; j < y + lat && j % 26 != 0; ++j)
                if(mat[i][j] > rez)
                    rez = mat[i][j];
            for(int j = y + lat - 1; j >= y && (j - 1) % 25 != 0; --j)
                if(mat[i][j] > rez)
                    rez = mat[i][j];
        }
        fprintf(fout, "%d\n", rez);
    }


    return 0;
}