Cod sursa(job #123493)
Utilizator | Data | 16 ianuarie 2008 11:12:14 | |
---|---|---|---|
Problema | Plus | Scor | 70 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.34 kb |
var v,c:array[0..4]of int64;
d:array[-300010..300010,0..3]of int64;
s,n,k,a,b,f,u,x,y:longint;
i,j:longint;
t:text;
begin
assign(t,'plus.in');
reset(t);
read(t,s);
read(t,c[1],v[1]);
read(t,c[2],v[2]);
read(t,c[3],v[3]);
close(t);
u:=c[1]+c[2]+c[3];
d[0,0]:=1;
for y:=1 to 3 do
if(v[y]=1)then begin x:=0;
for i:=-u-1 downto -u-c[y]-1 do
x:=x+d[i,y-1];
for i:=-u to u do
begin
x:=x+d[i,y-1];
x:=x-d[i-c[y]-1,y-1];
d[i,y]:=d[i,y]+x;
end;
end
else
if(v[y]=-1)then begin x:=0;
for i:=u+1 to u+c[y]+1 do
x:=x+d[i,y-1];
for i:=u downto -u do
begin
x:=x+d[i,y-1];
x:=x-d[i+c[y]+1,y-1];
d[i,y]:=d[i,y]+x;
end;
end
else
if(v[y]=0)then begin for i:=-u to u do
if d[i,y-1]>0 then d[i,y]:=d[i,y-1]+c[y];
end;
assign(t,'plus.out');
rewrite(t);
writeln(t,d[s,3]);
close(t);
end.