Cod sursa(job #232327)

Utilizator ioanacosteaIoana Costea ioanacostea Data 15 decembrie 2008 00:33:48
Problema Tablete Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.21 kb
var f:text;
    x1,x2,r,j,n,i,k:longint;
    z:longint;
begin
assign(f,'tablete.in');reset(f);
read(f,n,k);
{for i:=1 to n do for j:=1 to n do a[i,j]:=0;}
assign(f,'tablete.out');rewrite(f);
x2:=n*(k-1);x1:=0;
if x2 mod 2=0 then begin r:=x2; inc(x2); end else r:=0;
 for i:=1 to n-1 do
  begin
     for j:=1 to k-1 do
       begin inc(x1);
       write(f,x1,' ');
       end;
     if r<>0 then
     begin
      write(f,r,' ');
      r:=0;
      for j:=k+1  to n do
        begin inc(x2);write(f,x2,' '); end;
      end
      else
      begin
        inc(x2);
        write(f,x2,' ');
        for j:=k+1 to n-1 do
          begin
            inc(x2);write(f,x2,' ');
          end;
          inc(x2);
          r:=x2;
          inc(x2);
          write(f,x2,' ');
          end;

       writeln(f);
    end;
  for j:=1 to k-2 do begin inc(x1);write(f,x1,' '); end;
  if n*(k-1) mod 2=0 then write(f,n*(k-1)+1,' ') else write(f,n*(k-1), ' ');
  if r<>0 then begin
     write(f,r,' ');
     for j:=k+1 to n do
       begin
        inc(x2);write(f,x2,' ');
       end
       end
       else
     for j:=k to n do
       begin
        inc(x2);write(f,x2,' ');
       end;

 close(f);
end.