Pagini recente » Cod sursa (job #3140820) | Cod sursa (job #616143) | Cod sursa (job #1730094) | Cod sursa (job #69900) | Cod sursa (job #19504)
Cod sursa(job #19504)
var f,g:text;
a:array[1..50] of byte;
bool:array[1..50] of boolean;
b,c:array[1..2500] of integer;
i,j,k,n,u,t,p,l,r,s:longint;
soli,sol,sol1,sol2:boolean;
begin
assign(f,'amlei.in');
assign(g,'amlei.out');
reset(F);
rewrite(G);
while not eof(F) do
begin
readln(f,n,t,u);
for i:=1 to n*t do read(f,b[i]);
readln(F);
for i:=1 to n*u do read(f,c[i]);
readln(F);
p:=(1 shl n)-1; soli:=true;
i:=-1;
while (soli)and(i<p) do
begin
i:=i+1;
l:=i;
j:=n;
while l<>0
do begin
a[j]:=l mod 2;
l:=l div 2;
j:=j-1;
end;
for k:=1 to n do
if a[i]=0 then bool[k]:=false else bool[k]:=true;
j:=1;
sol1:=false;
while (not sol1)and(j<n*t) do
begin
sol:=true;
for r:=j to j+n-1 do
begin
if b[r]>0 then sol:=sol and bool[b[r]]
else sol:=sol and (not bool[abs(b[r])]);
if not sol then break;
end;
sol1:=sol1 or sol;
j:=j+n;
end;
j:=1;
sol2:=false;
while (not sol2)and(j<n*u) do
begin
sol:=true;
for r:=j to j+n-1 do
begin
if c[r]>0 then sol:=sol and bool[c[r]]
else sol:=sol and (not bool[abs(c[r])]);
if not sol then break;
end;
sol2:=sol2 or sol;
j:=j+n;
end;
soli:=sol1=sol2;
end;
if soli then writeln(g,'DA')
else writeln(g,'NU');
end;
close(F);
close(G);
end.