Cod sursa(job #152140)

Utilizator Clau2000GOREA CLAUDIU-CRISTIAN Clau2000 Data 9 martie 2008 03:07:00
Problema Xor Max Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.04 kb
var x:array[0..100000]of longint;
    aux,n,i,j,max,start, stop:longint;
    f,g:text;

begin
     assign(f,'xormax.in');
     assign(g,'xormax.out');
     reset(f);
     rewrite(g);
     read(f,n);
     x[0]:=0;
 {(a xor b=c) <=> (a=b xor c) <=> (a xor c=b)}
     for i:=1 to n do
     begin
          read(f,max);
          x[i]:=x[i-1] xor max;
     end;
     max:=0;
     for i:=2 to n do
         for j:=1 to i-1 do
         begin
            aux:=x[i] xor x[j];
            if (aux=max) and (i<stop) then
            begin
               start:=j+1;
               stop:=i;
            end else
               if (aux=max) and (i-j-1<stop-start) then
               begin
                  start:=j+1;
                  stop:=i;
               end else
                  if aux>max then
                  begin
                     max:=aux;
                     start:=j+1;
                     stop:=i;
                  end;
         end;
     write(g,max,' ',start,' ',stop);
     close(f);
     close(g);
end.