Cod sursa(job #2135599)

Utilizator waren4Marius Radu waren4 Data 18 februarie 2018 23:06:22
Problema Xor Max Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n,a[100005];

int main() {
    int j,i,x,y,m,k,s;
    f>>n;
    for(i = 1; i <= n; ++i) {
        f>>a[i];
    }
    m = -2000000000;
    for(k = 1; k <= n; ++k) {
        s = a[1];
        for(j = 2; j <= k; ++j) {
            s = s ^ a[j];
        }
        if (s > m) {
            m = s;
            x = 1;
            y = k;
        }
        for(i = j; i <= n; ++i) {
            s = s ^ a[i - k] ^ a[i];
            if (s > m) {
                m = s;
                x = i - k + 1;
                y = i;
            }
        }
    }
    g<<m<<' '<<x<<' '<<y;
    return 0;
}