Cod sursa(job #749497)

Utilizator Buzu_Tudor_RoCont vechi Buzu_Tudor_Ro Data 17 mai 2012 14:34:51
Problema Xor Max Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.65 kb
Program p1;
var a,c1,c2,poz,i,j1,j2,n,max,s:longint;
    bufi,bufa:array[0..1 shl 23] of char;
    x,y,sum:array[0..100000] of longint;
begin
    assign(input,'xormax.in'); reset(input);
    assign(output,'xormax.out'); rewrite(output);
    settextbuf(input,bufi); settextbuf(output,bufa);
    readln(n); read(a); s:=a; j1:=1; j2:=1; c1:=s; c2:=s; max:=0;

    for i:=2 to n do begin
                     read(a);
                     if (c1 xor a)>=a then c2:=c1 xor a
                                      else begin c2:=a; j1:=i; end;
                     if c2>=s then begin
                                  if c2>max then begin
                                                 max:=1;
                                                 s:=c2; j2:=i; poz:=j1;
                                                 x[max]:=poz;
                                                 y[max]:=j2;
                                                 sum[max]:=s;
                                                 end
                                             else begin
                                                  max:=max+1;
                                                  x[max]:=poz;
                                                  y[max]:=j2;
                                                  sum[max]:=s;
                                                  end;
                                  end;
                     c1:=c2;
                     end;
    c1:=x[1];
    c2:=y[1];

    for i:=1 to max do if (c1>=x[i]) and (c2<y[i]) then begin poz:=x[i]; j2:=y[i]; end;

    write(sum[max],' ',poz,' ',j2);

    close(input); close(output);
end.