Cod sursa(job #231880)
Utilizator | Data | 14 decembrie 2008 15:07:38 | |
---|---|---|---|
Problema | Tablete | Scor | 40 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 2.09 kb |
var i,j,k,l,s,n:integer;
begin
assign(input, 'tablete.in');
reset(input);
assign(output, 'tablete.out');
rewrite(output);
readln(n,k);
if (k mod 2=0) then
begin
if (n mod 2=0) then
for i:=0 to n-1 do
begin
for j:=1 to n do
write(i*n+j,' ');
writeln;
end
else
begin
for i:=0 to n-2 do
begin
for j:=1 to n do
write(i*(n+1)+j, ' ');
writeln;
end;
for i:=1 to n-1 do
write(i*(n+1),' ');
writeln(n*n);
end
end
else
begin
s:=0;
l:=1;
for i:=0 to n-2 do
begin
if (s=0) then
begin
write(l, ' ');
inc(l);
end
else
write(s, ' ');
write(l, ' ');
inc(l);
if (l mod 2 <> 0) then
begin
s:=l;
inc(l);
end
else
s:=0;
write(l,' ');
inc(l);
for j:=3 to n-1 do
if (j=n-1) and (i=n-2) then
write(n*n-1)
else
begin
write(l, ' ');
inc(l);
end;
writeln;
end;
if (s=0) then
begin
write(l,' ');
inc(l);
end
else
write(s, ' ');
write(l,' ');
inc(l);
for i:=0 to n-4 do
begin
write(l,' ');
inc(l);
end;
writeln(n*n);
end;
close(output);
close(input);
end.