Cod sursa(job #18426)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 18 februarie 2007 12:09:19
Problema Amlei Scor 10
Compilator fpc Status done
Runda preONI 2007, Runda 2, Clasa a 10-a Marime 1.68 kb
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.