Cod sursa(job #340324)

Utilizator doruletzPetrican Teodor doruletz Data 14 august 2009 11:33:37
Problema Tablete Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.2 kb
program x;
var n,k:0..2000;
      i,j,cont,a:0..2000000;
    m:array[0..2000,0..2000]of 0..2000000;
    t:text;
begin
 assign(t,'tablete.in'); reset(t);
 readln(t,n,k);
 close(t);
 if (k mod 2)=0 then
        begin
         for i:=1 to n do
          for j:=1 to k do begin
           inc(cont);
           m[i,j]:=cont;
          end;

         for i:=1 to n do
          for j:=k+1 to n do begin inc(cont); m[i,j]:=cont; end;
        end
 else
        begin
         for i:=1 to n do begin
           for j:=1 to k do begin
            inc(cont);
            if (j=k)and(i mod 2<>0) then m[i,j]:=cont+1 else
            if (j=1)and(i mod 2=0) then m[i,j]:=cont-1 else m[i,j]:=cont;
           end;
         end;

         if (n mod 2)=0 then
          for i:=1 to n do
           for j:=k+1 to n do begin inc(cont); m[i,j]:=cont; end;

         if (n mod 2)<>0 then begin
          a:=cont;
          for i:=1 to n do
           for j:=k+1 to n do begin inc(cont); m[i,j]:=cont; end;
          m[1,k+1]:=a-1;
         end;
        end;

 assign(t,'tablete.out'); rewrite(t);
 for i:=1 to n do begin
  for j:=1 to n do write(t,m[i,j],' ');
  writeln(t);
 end;
 close(t);
end.