Cod sursa(job #2738845)

Utilizator 6qqqqqqwwww wwww 6qqqqqq Data 6 aprilie 2021 14:15:34
Problema Xor Max Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>

using namespace std;

const int SIZE = 100005;
int pref[SIZE];

struct anstruct {
    int start, stop, x;
};

int main()
{
    ifstream cin ("xormax.in");
    ofstream cout("xormax.out");

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        int read;
        cin >> read;
        pref[i] = pref[i-1] ^ read;
    }
    //for(int i = 1; i <= n; i++)
    //    cout << pref[i] << " ";
    //cout << endl;

    anstruct ans = {-100000,100000,-1};
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            anstruct now = {j,i,(pref[j-1] ^ pref[i])};
            if((pref[j-1] ^ pref[i]) > ans.x)
                ans = now;
            else if((pref[j-1] ^ pref[i]) == ans.x)
            {
                if(i < ans.stop)
                    ans = now;
                else if(i == ans.stop)
                    if(j > ans.start)
                        ans = now;
            }
        }
    }

    cout << ans.x << " " << ans.start << " " << ans.stop;
    return 0;
}