Cod sursa(job #2902181)

Utilizator kanyjmkSabau Eduard kanyjmk Data 15 mai 2022 19:55:24
Problema Plantatie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
int plantatie[505][505][10];
int main()
{
    int n, m;
    fin >> n >> m;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            fin >> plantatie[i][j][0];
    for(int k = 1; (1<<k) <= n; ++k)
        for(int i = 1; i + (1<<k) -1 <= n; ++i)
            for(int j = 1; j+ (1<<k) -1 <= n; ++j)
                    plantatie[i][j][k]=max(max(plantatie[i][j][k-1],plantatie[i][j+(1<<(k-1))][k-1]),max(plantatie[i+(1<<(k-1))][j][k-1], plantatie[i+(1<<(k-1))][j+(1<<(k-1))][k-1]));
    for(int k = 1; k <= m; ++k)
    {
        int i, j, l, pow2;
        fin >> i >> j >> l;
        pow2 = log2(l);
        fout << max(max(plantatie[i+l-(1<<pow2)][j][pow2],plantatie[i+l-(1<<pow2)][j+l-(1<<pow2)][pow2]),max(plantatie[i][j][pow2],plantatie[i][j+l-(1<<pow2)][pow2])) << '\n';
    }
}