Cod sursa(job #2239021)

Utilizator Raoul_16Raoul Bocancea Raoul_16 Data 8 septembrie 2018 17:28:00
Problema Xor Max Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
const std :: string programName = "xormax";
std :: ifstream f(programName + ".in");
std :: ofstream g(programName + ".out");
const int NMAX = 1E5;
int main() {
    int N, v[NMAX + 5], Xcopy = -1, Xcopy2 = -1, max = -1;
    f >> N;
    for (int i = 1; i <= N; ++i)
        f >> v[i];
    for (int i = 1; i <= N; ++i) {
        int S = 0;
        for (int j = i; j <= N; ++j) {
            S ^= (v[i] ^ v[j]);
            if (S > max or (S == max and j - i < Xcopy2 - Xcopy)) {
                max = S;
                Xcopy = i;
                Xcopy2 = j;
            }
        }
    }
    g << max << ' ' << Xcopy << ' ' << Xcopy2 << "\n";
    return 0x0;
}