Cod sursa(job #1313654)

Utilizator thesvcoolmanLucian Bicsi thesvcoolman Data 10 ianuarie 2015 22:23:17
Problema Xor Max Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<fstream>
#include<vector>

using namespace std;

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

vector<long long> V;
long long n, elem, xormax, b, e, SUM;

int main() {
    fin>>n;
    for(int i=1; i<=n; i++) {
        fin>>elem;
        V.push_back(elem);
    }


    for(int i=n-1; i>=0; i--) {
        SUM = 0;
        for(int j=i; j>=0; j--) {
            SUM ^= V[j];
            if(SUM > xormax || (SUM == xormax and (i<e || (i == e and j > b)))) {
                xormax = SUM;
                b = j;
                e = i;
            }
        }
    }
    fout<<xormax<<" "<<b+1<<" "<<e+1;

    return 0;
}