Pagini recente » Cod sursa (job #700085) | Cod sursa (job #1352593) | Cod sursa (job #258514) | Cod sursa (job #935946) | Cod sursa (job #1586058)
#include <stdio.h>
#include <stdlib.h>
int main()
{
freopen("xormax.in", "r", stdin);
freopen("xormax.out", "w", stdout);
unsigned long int n, i, j, *ma, *also, *felso, *cs, maxi = 0, start, endd;
scanf("%d", &n);
ma = (unsigned long int*) malloc (n* sizeof(unsigned long int));
for(i = 0; i < n; ++i)
{
scanf("%lu", ma+i);
}
if(n == 1)
{
printf("%lu %lu %lu", ma[0], 1,1);
return 0;
}
felso = (unsigned long int*) malloc ((n-1) * sizeof(unsigned long int));
also = (unsigned long int*) malloc ((n-1) * sizeof(unsigned long int));
felso[0] = ma[0] ^ ma[1];
for(i = 1; i < n - 1; ++i)
{
also[0] = felso[0] ^ ma[i+1];
if(also[0] > maxi)
{
maxi = also[0];
start = i;
endd = i+1;
}
for(j = 1; j <= i; ++j)
{
also[j] = also[ j-1 ] ^ ma[j-1];
if(also[j] >= maxi)
{
maxi = also[j];
start = j+1;
endd = i+2;
}
}
cs = felso;
felso = also;
also = cs;
}
printf("%lu %lu %lu", maxi, start, endd);
return 0;
}