Cod sursa(job #18216)

Utilizator floringh06Florin Ghesu floringh06 Data 18 februarie 2007 10:44:03
Problema Plantatie Scor 10
Compilator fpc Status done
Runda preONI 2007, Runda 2, Clasa a 10-a Marime 1.48 kb
{$IFDEF NORMAL}
  {$I-,Q-,R-,S-}
{$ENDIF NORMAL}
{$IFDEF DEBUG}
  {$I+,Q+,R+,S-}
{$ENDIF DEBUG}
{$IFDEF RELEASE}
  {$I-,Q-,R-,S-}
{$ENDIF RELEASE}

var fi,fo:text;
    i,j,n,p,m,k:longint;
   // m:array[1..505,1..505] of longword;
    opt:array[1..505,1..505,1..505] of longword;




  function max(a,b:longword):longword;
   begin
    if a>b then max:=a
      else max:=b;
   end;

  function min(a,b:longword):longword;
   begin
    if a<b then min:=a
     else min:=b;
   end;


  procedure comp;
   var i,j,p,maxx1,maxx2,mm,ii,jj,k:longword;
    begin
      for i:=1 to n do
       for j:=1 to n do
        for k:=2 to min(n-i+1,n-j+1) do
         begin
           maxx1:=opt[i+k-1,j,1];
           for jj:=j to j+k-1 do
             if opt[i+k-1,jj,1]>maxx2 then maxx2:=opt[i+k-1,jj,1];
           maxx2:=opt[i,j+k-1,1];
           for ii:=i to i+k-1 do
             if opt[ii,j+k-1,1]>maxx1 then maxx1:=opt[ii,j+k-1,1];
           mm:=max(maxx1,maxx2);
           opt[i,j,k]:=max(opt[i,j,k-1],mm);
         end;
    end;






begin
 assign(fi,'plantatie.in'); reset(fi);
 assign(fo,'plantatie.out'); rewrite(fo);
 readln(fi,n,m);
 for i:=1 to n do
  for j:=1 to n do
    read(fi,opt[i,j,1]);
 comp;
 readln(fi);
 for k:=1 to m do
  begin
   readln(fi,i,j,p);
   writeln(fo,opt[i,j,p]);
  end;
{ for i:=1 to n do
  begin
   for j:=1 to n do
    write(fo,opt[i,j,2]:3);
   writeln(fo);
  end;       }

close(fi);
close(fo);
end.