Cod sursa(job #7917)

Utilizator andrewgPestele cel Mare andrewg Data 22 ianuarie 2007 22:56:05
Problema 1-sir Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.85 kb
const maxn = 33000;
      modulo = 194767;

var f:text;
    n,k,s,i,j,sol,max:longint;
    c:array[0..maxn]of longint;

procedure readdata;
begin
   assign(f,'1-sir.in');
   reset(f);
   readln(f,n,k);
   s:=n*(n-1) div 2;
   s:=s-k;
   sol:=0;
   if s mod 2<>0 then
   begin
      sol:=-1;
   end;
   s:=s div 2;
   close(f);
end;

procedure solve;
begin
   c[0]:=1;
   max:=0;
   for i:=1 to n-1 do
   begin
      for j:=max downto 0 do
      begin
         if c[j]<>0 then
         begin
            if (i+j<=s) then c[i+j]:=(c[i+j]+c[j]) mod modulo;
         end;
      end;
      max:=max+i;
   end;
end;

procedure writedata;
begin
   assign(f,'1-sir.out');
   rewrite(f);
   if sol<>-1 then writeln(f,c[s])
              else writeln(f,0);
   close(f);
end;

begin
   readdata;
   solve;
   writedata;
end.