Cod sursa(job #193218)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 2 iunie 2008 23:04:02
Problema Plantatie Scor 50
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.78 kb
   Program cel;  
    Type {matrice=array[1..500,1..500] of longint;   }  
         tablou=array[1..500,1..500,1..500] of word;  
   var f,g:text;  
      { a:matrice;}  
       b:tablou;  
       max,p,w:longint;  
       n,m,i,j,k:integer;  
   procedure maxim(var max:longint;i,j,k:integer);  
   Begin  
    If max<b[i,j,k] then max:=b[i,j,k];  
   end;  
    
   Begin  
   Assign(f,'plantatie.in');Reset(f);  
   Assign(g,'plantatie.out');Rewrite(g);  
   Readln(f,n,m);  
   {For i:=1 to n do 
    Begin 
     For j:=1 to n do Read(f,a[i,j]); 
     Readln(f); 
    end; }  
   k:=1;  
   While k<=n do  
    Begin  
     i:=1;  
     While i<=n-k+1 do  
      Begin  
       j:=1;  
       While j<=n-k+1 do  
        Begin  
         If k=1 then Begin  
                     Read(f,w);  
                      b[i,j,k]:=w;  
                     end  
                else Begin  
                      max:=b[i,j,k div 2];  
                     maxim(max,i,j+k div 2,k div 2);  
                  maxim(max,i+k div 2,j,k div 2);  
                      maxim(max,i+k div 2,j+k div 2,k div 2);  
                      b[i,j,k]:=max;  
                     end;  
          j:=j+1;  
         end;  
        If k=1 then Readln(f);  
        i:=i+1;  
       end;  
      k:=k*2;  
   end;  
    
  For w:=1 to m do  
    Begin  
   Readln(f,i,j,k);  
    If k=1 then Writeln(g,b[i,j,k])  
          else Begin  
                 p:=1;  
                 While p*2<=k do p:=p*2;  
     max:=b[i,j,p];  
     If max<b[i,j+k-p,p] then max:=b[i,j+k-p,p];  
     If max<b[i+k-p,j,p] then max:=b[i+k-p,j,p];  
     If max<b[i+k-p,j+k-p,p] then max:=b[i+k-p,j+k-p,p];  
     Writeln(g,max);  
    end;  
    end;  
   Close(f);  
   Close(g);  
   end.