Cod sursa(job #2902169)

Utilizator kanyjmkSabau Eduard kanyjmk Data 15 mai 2022 19:31:36
Problema Plantatie Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
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 <= n; i++)
            for(int j = 1; j <= 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 = 0;
        fin >> i >> j >> l;
        while((1<<pow2)<<1 <= l)
            pow2++;
        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+k-(1<<pow2)][pow2])) << '\n';
    }
}