Cod sursa(job #3153602)

Utilizator Luka77Anastase Luca George Luka77 Data 30 septembrie 2023 13:17:07
Problema Xor Max Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <bits/stdc++.h>
#define FOR(n) for(int i = 1; i <= n; ++ i)
using namespace std;

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

/// GLOBAL VARIABLES
const int NMAX = 1e5 + 5;
int n, ans, st, dr, min_cnt;
int arr[NMAX];

/// SOLUTIA BRUTA
int main()
{
    ios::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);

    fin >> n;

    FOR(n)
        fin >> arr[i];

    for(int i = 1; i < n; ++ i)
    {
        int cnt = 1;
        int xor_max = arr[i];
        if(xor_max == ans)
        {
            st = i, dr = i;
        }
        if(xor_max > ans)
        {
            ans = xor_max;
            st = i, dr = i;
        }
        for(int j = i + 1; j <= n; ++ j)
        {
            cnt++;
            xor_max^=arr[j];
            if(xor_max == ans && j <= dr && cnt < min_cnt)
            {
                st = i;
                dr = j;
                min_cnt = cnt;
            }
            else if(xor_max == ans && j < dr)
            {
                st = i;
                dr = j;
            }
            else if(xor_max > ans)
            {
                ans = xor_max;
                st = i, dr = j;
            }
        }
    }
    fout << ans << ' ' << st << ' ' << dr << '\n';
}