Pagini recente » Cod sursa (job #2584176) | Cod sursa (job #791135) | Cod sursa (job #2718377) | Cod sursa (job #490413) | Cod sursa (job #23470)
Cod sursa(job #23470)
var a: array[1..500,1..500,0..10] of longint;
n,m,x,d,i,j,h,nn,rez: longint;
function max(a,b: longint): longint;
begin
if (a<b) then max:=b
else max:=a;
end;
begin
assign(input,'plantatie.in'); reset(input);
read(n,m);
for i:=1 to n do
for j:=1 to n do read(a[i][j][0]);
nn:=trunc(ln(n)/ln(2));
for d:=1 to nn do
for i:=1 to n do
for j:=1 to n do
begin
a[i][j][d]:=max(a[i][j][d-1],a[i][j+(1 shl (d-1))][d-1]);
a[i][j][d]:=max(a[i][j][d],a[i+(1 shl (d-1))][j][d-1]);
a[i][j][d]:=max(a[i][j][d],a[i+(1 shl (d-1))][j+(1 shl (d-1))][d-1]);
end;
assign(output,'plantatie.out'); rewrite(output);
for x:=1 to m do
begin
read(i,j,d);
nn:=trunc(ln(d)/ln(2));
h:=d-(1 shl (nn));
rez:=max(a[i][j][nn],a[i][j+h][nn]);
rez:=max(rez,a[i+h][j][nn]);
rez:=max(rez,a[i+h][j+h][nn]);
writeln(rez);
end;
close(output);
end.