Cod sursa(job #738636)

Utilizator mirceadinoMircea Popoveniuc mirceadino Data 21 aprilie 2012 11:17:41
Problema Xor Max Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<cstdio>
int i,n,max=0,last,start,stop,startmax,stopmax,a;
int main()
{
    freopen("xormax.in","r",stdin);
    freopen("xormax.out","w",stdout);
    scanf("%d",&n); start=1; stop=1;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        if((last^a)>=a)
        {
            last=last^a;
            stop++;
            if(last>max) {max=last; startmax=start; stopmax=stop;}
        }
        else
        {
            if((last>max)||(((stop-start)<(stopmax-startmax))&&(last==max)))
            {
                max=last; startmax=start; stopmax=stop;
            }
            last=a;
            start=i; stop=i;
        }
    }
    printf("%d %d %d\n",max,startmax,stopmax);
    return 0;
}