Cod sursa(job #20859)

Utilizator vanila0406Ionescu Victor vanila0406 Data 22 februarie 2007 15:39:45
Problema Amlei Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 3.99 kb
program amlei;
type vector=array[1..501] of qword;
var f,g:text;
        n,u,t,w:longint;
        v,e1,e2:vector;


procedure iofile;
begin
        assign(f,'amlei.in');
        reset(f);
        assign(g,'amlei.out');
        rewrite(g);
end;


procedure pozitie(var v:vector;var m:longint;p,u:longint);
var i,j,di,dj,aux:longint;
        aux1:qword;
begin
        i:=p;
        j:=u;
        di:=0;
        dj:=-1;
        while i<j do
                begin
                        if v[i]>v[j] then
                                begin
                                        aux:=di;
                                        di:=-dj;
                                        dj:=-aux;
                                        aux1:=v[i];
                                        v[i]:=v[j];
                                        v[j]:=aux1;
                                end;
                        i:=i+di;
                        j:=j+dj;
                end;
        m:=i;
end;



procedure quick(p,u:longint;var v:vector);
var m:longint;
begin
        if p<u then
                begin
                        pozitie(v,m,p,u);
                        quick(p,m-1,v);
                        quick(m+1,u,v);
                end;
end;



function este(x:qword;var v:vector;var n:longint):boolean;
var i:longint;
begin
        este:=false;
        for i:=1 to n do
                if v[i]=x then
                        begin
                                este:=true;
                                exit;
                        end;
end;




procedure prel;
var i,j,k,lv1,lv2,x:longint;
        s:qword;
        ok:boolean;
begin
        while not(eof(f)) do
                begin
                        readln(f,n,t,u);
                        lv1:=0;
                        for j:=1 to t do
                            begin
                                s:=0;
                                for k:=1 to n do
                                    begin
                                                read(f,x);
                                                if x<0 then
                                                s:=s+1 shl(abs(x)-1);
                                    end;
                                if not(este(s,e1,lv1)) then
                                        begin
                                inc(lv1);
                                e1[lv1]:=s;  end;
                            end;
                        quick(1,lv1,e1);
                        lv2:=0;
                        for j:=1 to u do
                            begin
                                s:=0;
                                for k:=1 to n do
                                    begin
                                                read(f,x);
                                                if x<0 then
                                                s:=s+1 shl(abs(x)-1);
                                    end;
                                if not (este(s,e2,lv2)) then
                                        begin
                                inc(lv2);
                                e2[lv2]:=s;  end;
                            end;
                        quick(1,lv2,e2);
                        ok:=true;
                        if lv1<>lv2 then
                                ok:=false else
                                for j:=1 to lv1 do
                                        if e1[j]<>e2[j] then
                                                begin
                                                        ok:=false;
                                                        break;
                                                end;
                        if ok=true then
                                writeln(g,'DA') else
                                writeln(g,'NU');
                        readln(f);
                end;
        close(g);
end;



begin
        iofile;
        prel;
end.