Cod sursa(job #1706809)

Utilizator MotoAMotoi Alexandru MotoA Data 23 mai 2016 12:24:32
Problema Xor Max Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("xormax.in");
ofstream g("xormax.out");
int main()
    {
    int n, smax = 0, k, p, x[100001] = {0}, s, in , stop, a;
    f >> n;
    for(k = 1; k <= n; k++)
        {
        f >> a;
        x[k] = x[k - 1] ^ a;
        }
    for(k = 1; k <= n - 1; k++)
        for(p = k; p <= n; p++)
            {
            s = x[p] ^ x[k - 1];
            if(s > smax)
                {
                smax = s;
                in = k;
                stop = p;
                }
            else
                if(s == smax && p < stop)
                    {
                    smax = s;
                    in = k;
                    stop = p;
                    }
            }
    g << smax << ' ' << in << ' ' << stop;
    return 0;
    }