Cod sursa(job #1865455)

Utilizator loghin.alexandruLoghin Alexandru loghin.alexandru Data 1 februarie 2017 19:28:07
Problema Xor Max Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb

#include <fstream>
#include <vector>

std::ifstream fin("xormax.in");
std::ofstream fout("xormax.out");


std::vector<int> numbers;


void read(unsigned int length)
{
	int n = 0;

	for (auto i = 0; i < length; i++)
	{
		fin >> n;
		numbers.push_back(n);
	}
}


int main()
{
	int sum = 0;
	int i = 0;
	int p = 0;
	int stop = 0;
	int lungime = 0, n = 0, max = 0;
	fin >> n;
	read(n);
	if (n > 0)
	{
		max = numbers[0];
		sum = numbers[0];
	}
	else
	{
		fout << 0 << ' ' << 0 << ' ' << 0;
		return 0;
	}
	for (auto& container : numbers)
	{
		if (i>0)
		{
			p = container ^ sum;
		}
		if (p > max)
		{
			max = p;
			sum += p;
			lungime++;
			stop = i;
		}
		else
		{
			lungime = 1;
			sum = container;
		}
		i++;
	}
	fout << max << ' ' << stop + 2 - lungime << ' ' << stop + 1;
	return 0;
}