Cod sursa(job #2168953)

Utilizator cicero23catalin viorel cicero23 Data 14 martie 2018 12:54:29
Problema Plantatie Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
int m[501][501][11];
int main()
{
    int n,q,k,i,j,z,l;
    f>>n>>q;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
    {
        f>>m[i][j][0];
    }
    for(k=1;(1<<k)<=n;k++)
        for(i=1;i<=n-(1<<(k-1));i++)
        for(j=1;j<=n-(1<<(k-1));j++)
    {
        m[i][j][k]=max(max(m[i][j][k-1],m[i+(1<<(k-1))][j][k-1]),max(m[i+(1<<(k-1))][j+(1<<(k-1))][k-1],m[i][j+(1<<(k-1))][j-1]));
    }
    for(k=1;k<=q;k++)
    {
        f>>i>>j>>l;
        z=log2(l);
        g<<max(max(m[i][j][z],m[i+l-(1<<z)][j][z]),max(m[i][j+l-(1<<z)][z],m[i+l-(1<<z)][j+l-(1<<z)][z]))<<'\n';
    }
    return 0;
}