Pagini recente » Cod sursa (job #233915) | Cod sursa (job #114103) | Cod sursa (job #3169703) | Cod sursa (job #1399585) | Cod sursa (job #1647523)
#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, h;
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 * sizeof(unsigned long int));
also = (unsigned long int*) malloc (n * 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;
}
//printf("%d ", also[0]);
for(j = 1; j < i; ++j)
{
also[j] = also[ j-1 ] ^ ma[j + 1];
if(also[j] >= maxi && (also[j] > maxi || endd > i+2 || endd - start > j + i + 3) )
{
maxi = also[j];
start = j+1;
endd = i+2;
}
// printf("%d ", also[j]);
}
//printf("\n");
cs = felso;
felso = also;
also = cs;
}
printf("%lu %lu %lu", maxi, start, endd);
return 0;
}