Cod sursa(job #1395148)

Utilizator nickulNic Kul nickul Data 21 martie 2015 01:30:15
Problema Xor Max Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<fstream>
#include<vector>

using namespace std;

ifstream in("xormax.in");
ofstream out("xormax.out");

int main()
{
	size_t n,x,i,j,max=0,start,stop;
	vector<size_t> v;
	v.push_back(0);
	in>>n;
	for(i=1;i<=n;i++)
	{
		in>>x;
		v.push_back(v[v.size()-1]^x);
	}
	for(i=2;i<=n;i++)
		for (j=0;j<i;j++)
		{
			x=v[i]^v[j];
			if (x>max)
			{
				max=x;
				start=j+1;
				stop=i;
			}
			else
				if (x==max)
				{
					if(stop>i)
					{
						stop=i;
						start=j+1;
					}
					else
						if(stop==i&&start<j+1)
						{
							start=j+1;
						}
				}
		}
		out<<max<<' '<<start<<' '<<stop;
}