Cod sursa(job #7025)

Utilizator hitmannCiocas Radu hitmann Data 21 ianuarie 2007 11:53:16
Problema 1-sir Scor 0
Compilator fpc Status done
Runda preONI 2007, Runda 1, Clasele 11-12 Marime 1.16 kb
var st:array[1..256] of longint;
    n,i,j,k:integer;
    s:int64;
    as,ev:boolean;
    g:text;
procedure citire;
var f:text;
begin
assign(f,'1-sir.in'); reset(f);
read(f,n,s); close(f);
end;
procedure init;
begin
st[k]:=-n;
end;
procedure succesor;
begin
if k<>1 then if st[k]<n then
                        begin
                        inc(st[k]);
                        as:=true;
                        end
                        else as:=false;
end;
procedure valid;
var x:int64;
begin
ev:=true;
x:=0;
if st[1]<>0 then ev:=false;
i:=2;

while (i<=k)and ev do
 begin
 x:=x+st[i];
 if x>s then ev:=false;
 if abs(st[i-1]-st[i])<>1 then ev:=false;
 inc(i);
 end;
 if k=n then if x<>s then ev:=false;
end;
begin {pp}
citire;
k:=2;
init;
while k>1 do
 begin
 repeat
 succesor;
 if as then valid;
 until not as or(as and ev);
 if as then if k=n then begin
                        inc(j);
                        for i:=1 to n do write(st[i],' ');
                        end
                   else begin inc(k); init; end
       else dec(k);
 end;
assign(g,'1-sir.out');rewrite(g);
write(g,j mod 194767);
close(g);
end.