Cod sursa(job #1395153)

Utilizator nickulNic Kul nickul Data 21 martie 2015 01:37:59
Problema Xor Max Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 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,bitmax=0;
	vector<size_t> v,v2;
	v.push_back(0);
	in>>n;
	for(i=1;i<=n;i++)
	{
		in>>x;
		if(x>>bitmax)
		{
			while(x>>bitmax) bitmax++;
			v2.resize(0);
		}
		if(x>>(bitmax-1))
		{
			v2.push_back(v.size());
		}
		v.push_back(v[v.size()-1]^x);
	}
	for(i=v2[0];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;
						}
				}
		}
		if(x==(1<<(bitmax+1))-1) break;
	}
	out<<max<<' '<<start<<' '<<stop;
}